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