From 90cd115eac072a83b31dbd56799743923170d208 Mon Sep 17 00:00:00 2001 From: Viktoriia Roik Date: Fri, 4 Aug 2023 20:11:24 +0200 Subject: [PATCH] add task solution --- src/arrayMethodJoin.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c1..fbcf49047 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,8 +4,21 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here + [].__proto__.join2 = function(separator = ',') { + const arrLength = this.length; + let joinedString = ''; + + for (let i = 0; i < arrLength; i++) { + if (this[i] !== null && this[i] !== undefined) { + joinedString += this[i]; + } + + if (i !== arrLength - 1) { + joinedString += separator; + } + } + + return joinedString; }; }