From 71a0cce0949b498469c86180292e238956238474 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Tue, 15 Aug 2023 09:58:57 +0300 Subject: [PATCH] solution --- src/arrayMethodJoin.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..122e863d 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,9 +4,20 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here - }; -} + [].__proto__.join2 = function(separator = ',') { + let result = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + result += this[i]; + } + if (i < this.length - 1) { + result += separator; + } + } + + return result; + }; +}; module.exports = applyCustomJoin;