diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..1385d0f6 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,9 +4,22 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here + [].__proto__.join2 = function(separator = ',') { + let joinedString = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + joinedString += this[i]; + } + + if (i < this.length - 1) { + joinedString += separator; + } + } + + return joinedString; }; } + module.exports = applyCustomJoin;