From d0fbb45a68440c9d243a3ffed15e3b2dd3793669 Mon Sep 17 00:00:00 2001 From: Liliya Kalinichenko Date: Mon, 14 Aug 2023 16:12:44 +0300 Subject: [PATCH] solution was added --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..cbf86bf4 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,8 +4,20 @@ * 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; }; }