diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..d258dce1 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,8 +5,26 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + let result = ''; + + let sep = separator; + + if (sep === undefined) { + sep = ','; + } + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + result += this[i]; + } + + if (i !== this.length - 1) { + result += sep; + } + } + + return result; }; -} +}; module.exports = applyCustomJoin;