Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
navrotskymetra committed Jul 31, 2023
1 parent d04c9f0 commit 6eb7349
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
let result = '';

let sep = separator;

if (sep === undefined) {
sep = ',';
}

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

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

return result;
};
}
};

module.exports = applyCustomJoin;

0 comments on commit 6eb7349

Please sign in to comment.