Skip to content

Commit

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

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

for (let i = 0; i <= this.length - 1; i++) {
if (
(this[i] === null || this[i] === undefined)
&& i === this.length - 1) {
break;
}

if (this[i] === null || this[i] === undefined) {
newString += sepanullator;
continue;
}

if (i === this.length - 1) {
newString += this[i];
break;
}

newString += this[i] + sepanullator;
}

return newString;
};
}

Expand Down

0 comments on commit 265e9ac

Please sign in to comment.