Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #2682

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

solution #2682

wants to merge 5 commits into from

Conversation

AndrMar1939
Copy link

No description provided.

Copy link

@dffUqp dffUqp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done:smiley:

// write code here
[].__proto__.join2 = function(separator = ',') {
const currentArrayLength = this.length;
const joinSeparator = separator + '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use a more readable string transform for it.

Suggested change
const joinSeparator = separator + '';
const joinSeparator = String(separator);

this.forEach((item, index) => {
/* const stringCharacter = item ?? '' is the best choice,
but I couldn`t disable eslint for the nullish operator */
const stringCharacter = item === null || item === undefined
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it shorter using ==

console.log(undefined == null) // true

console.log(null == null)  // true

console.log(false == null) // false

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using == is very dangerous for our karma)

Comment on lines 23 to 25
currentArrayLength - 1 === index
? resultingString += stringCharacter
: resultingString += stringCharacter + joinSeparator;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to use if statement here because it makes our code more readable.

@AndrMar1939 AndrMar1939 requested a review from dffUqp August 7, 2023 06:43
Copy link

@Moroz-Dmytro Moroz-Dmytro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ 🚀
But let's make your code clearer

// write code here
[].__proto__.join2 = function(separator = ',') {
const currentArrayLength = this.length;
const joinSeparator = String(separator);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?
I guess result will be the same with and without String()
image

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrMar1939 reply to it

Comment on lines 12 to 14
if (!currentArrayLength) {
return resultingString;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?
If length === 0 we will skip forEach and also return resultingString

Comment on lines 23 to 27
if (currentArrayLength - 1 === index) {
resultingString += stringCharacter;
} else {
resultingString += stringCharacter + joinSeparator;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need else here? Maybe we can simplify this and use only if?
P.S. We do the same part of logic in if and in else block

const joinSeparator = String(separator);
let resultingString = '';

this.forEach((item, index) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Array methods is prohibited in this task. Use loops, index access, and array length if needed.

// write code here
[].__proto__.join2 = function(separator = ',') {
const currentArrayLength = this.length;
const joinSeparator = String(separator);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrMar1939 reply to it

Comment on lines +23 to +24
resultingString += stringCharacter;
resultingString += separator;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's simplify this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants