Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk177m committed Jul 30, 2023
1 parent d04c9f0 commit a7cbe0d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
let joinArray = '';
let secondSeparator = separator;

if (separator === null) {
secondSeparator = 'null';
}

for (let i = 0; i < this.length; i++) {
if (this[i] !== null && this[i] !== undefined) {
if (i === this.length - 1) {
joinArray += this[i];
} else {
joinArray += this[i] + secondSeparator;
}
} else {
if (i !== this.length - 1) {
joinArray += secondSeparator;
}
}
}

return joinArray;
};
}

Expand Down

0 comments on commit a7cbe0d

Please sign in to comment.