Skip to content
Open
Changes from all 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 = '';

if (separator === undefined) {
// eslint-disable-next-line no-param-reassign
separator = ',';
}
Comment on lines +10 to +13

Choose a reason for hiding this comment

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

you don't need to mutate argument of function. You can just set default value for the separator

Suggested change
if (separator === undefined) {
// eslint-disable-next-line no-param-reassign
separator = ',';
}


for (let i = 0; i < this.length; i++) {
if (this[i] !== null && this[i] !== undefined) {
result += this[i];
}

if (i !== this.length - 1) {
result += separator;
}
}

return result;
};
}

Expand Down