From 0b2773977e1b49b2fae998c6ce41e8a5f5f105b3 Mon Sep 17 00:00:00 2001 From: AntonFof Date: Sat, 29 Mar 2025 15:49:27 +0200 Subject: [PATCH 1/2] mySolution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..35557402 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 string = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + string += this[i]; + } + + if (i !== this.length - 1) { + string += separator; + } + } + + return string; }; } From 538b370bbbd1e33ce846bdcd65b95f5a5f12a34f Mon Sep 17 00:00:00 2001 From: AntonFof Date: Sat, 29 Mar 2025 16:12:46 +0200 Subject: [PATCH 2/2] mySolution --- src/arrayMethodJoin.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 35557402..ba32a6ad 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,20 +4,25 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator = ',') { - let string = ''; + [].__proto__.join2 = function(separator) { + let result = ''; + + if (separator === undefined) { + // eslint-disable-next-line no-param-reassign + separator = ','; + } for (let i = 0; i < this.length; i++) { if (this[i] !== null && this[i] !== undefined) { - string += this[i]; + result += this[i]; } if (i !== this.length - 1) { - string += separator; + result += separator; } } - return string; + return result; }; }