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

add task solution #2639

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

Conversation

MateuszSlezak
Copy link

No description provided.

Copy link

@choeqq choeqq left a 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 🚀

// write code here
[].__proto__.join2 = function(separator = ',') {
let newString = '';
let sepanullator = separator;
Copy link

Choose a reason for hiding this comment

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

what's sepanullator? 😄

Comment on lines 11 to 13
if (separator === null) {
sepanullator = 'null';
}
Copy link

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 ','

Copy link
Author

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');
});

Comment on lines 16 to 32
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;
Copy link

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 🔽

Suggested change
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
}

Copy link

@choeqq choeqq left a 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 👀

Copy link

@choeqq choeqq left a 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 ✅

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.

2 participants