Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszSlezak committed Aug 1, 2023
1 parent 265e9ac commit 8f5b00e
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,16 @@
function applyCustomJoin() {
[].__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) {
if (this[i] !== undefined && this[i] !== null) {
newString += this[i];
break;
}

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

return newString;
};
Expand Down

0 comments on commit 8f5b00e

Please sign in to comment.