diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index c83f48bb..5b3d6d8b 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -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; };