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

added solution task #2748

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {

Choose a reason for hiding this comment

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

Suggested change
[].__proto__.join2 = function(separator) {
[].__proto__.join2 = function(separator = ',') {

// write code here
let result = '';
const readySeparator = separator !== undefined ? String(separator) : ',';

Choose a reason for hiding this comment

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

default value looks more readable


for (let i = 0; i < this.length; i++) {
let value = this[i];

if (value === undefined || value === null) {
value = '';
}

if (i === 0) {
result += value;
} else {
result += readySeparator + value;
}

Choose a reason for hiding this comment

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

Suggested change
let value = this[i];
if (value === undefined || value === null) {
value = '';
}
if (i === 0) {
result += value;
} else {
result += readySeparator + value;
}
let value = this[i];
if (value !== undefined && value !== null) {
result += value;
}
if (i !== this.length - 1) {
result += readySeparator;
}

}

return result;
};
}

Expand Down