From bf0990eda2d2636cb72ca1cfc7b9adb30fb3315b Mon Sep 17 00:00:00 2001 From: Patryk-Buczkowski Date: Wed, 16 Aug 2023 17:35:43 +0200 Subject: [PATCH] solution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..49a0b630 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 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; }; }