-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
add task solution #2639
base: master
Are you sure you want to change the base?
add task solution #2639
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, small changes needed 🚀
src/arrayMethodJoin.js
Outdated
// write code here | ||
[].__proto__.join2 = function(separator = ',') { | ||
let newString = ''; | ||
let sepanullator = separator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's sepanullator? 😄
src/arrayMethodJoin.js
Outdated
if (separator === null) { | ||
sepanullator = 'null'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separator won't ever be null - we have defaultet it to ','
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah was sure i need this for this test: test
source = [0, 1, 2, 3];
(Should work with null
, () => {
expect(source.join2(null))
.toBe('0null1null2null3');
});
src/arrayMethodJoin.js
Outdated
if ( | ||
(this[i] === null || this[i] === undefined) | ||
&& i === this.length - 1) { | ||
break; | ||
} | ||
|
||
if (this[i] === null || this[i] === undefined) { | ||
newString += sepanullator; | ||
continue; | ||
} | ||
|
||
if (i === this.length - 1) { | ||
newString += this[i]; | ||
break; | ||
} | ||
|
||
newString += this[i] + sepanullator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is way easier to check for cases when we want to apply logic, instead of getting rid of everyone single other one 🔽
if ( | |
(this[i] === null || this[i] === undefined) | |
&& i === this.length - 1) { | |
break; | |
} | |
if (this[i] === null || this[i] === undefined) { | |
newString += sepanullator; | |
continue; | |
} | |
if (i === this.length - 1) { | |
newString += this[i]; | |
break; | |
} | |
newString += this[i] + sepanullator; | |
if (this[i] !== null && this[i] !== undefined) { | |
newString += String(this[i]) | |
} | |
if (i < this.length - 1) { | |
newString += separator | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for any updates @MateuszSlezak 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, nicely done ✅
No description provided.