Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
in7264 committed Jul 30, 2023
1 parent d04c9f0 commit 18bb794
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 @@ -4,8 +4,26 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
if (this.length === 0) {
return '';
}

let newArray = '';

for (let i = 0; i < this.length; i++) {
if (this[i] === undefined || this[i] === null) {
newArray += '';
} else {
newArray += this[i];
}

if (i < this.length - 1) { // no separator will be added to last element
newArray += separator;
}
}

return newArray;
};
}

Expand Down

0 comments on commit 18bb794

Please sign in to comment.