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