diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..53c19827 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -3,9 +3,30 @@ /** * Implement method join */ + function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + const { sep } = { sep: separator === undefined ? ',' : String(separator) }; + + let result = ''; + + for (let i = 0; i < this.length; i++) { + if (i > 0) { + result += sep; + } + + if (this[i] === null || this[i] === undefined) { + result += ''; + } else { + if (String(this[i]) === 'null') { + result += 'null'; + } else { + result += String(this[i]); + } + } + } + + return result; }; }