diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..568d471c 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,8 +4,19 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { + [].__proto__.join2 = function(separator = ',') { // write code here + let resultString = ''; + + for (let i = 0; i < this.length; i++) { + if (typeof (this[i]) !== 'undefined' && this[i] !== null) { + resultString += `${this[i]}`; + } + + resultString += `${i < this.length - 1 ? separator : ''}`; + } + + return resultString; }; }