From 00b9cbcfacd92ffc138c45d953101b9d9c32f1cb Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 17 Aug 2023 00:15:04 +0300 Subject: [PATCH 1/3] solution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..9048b32a 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 resultString = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + resultString += this[i]; + } + + if (i !== this.length - 1) { + resultString += separator; + } + } + + return resultString; }; } From c2f7a7512f14dfc895659186124bad2017f89dfd Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 17 Aug 2023 13:16:45 +0300 Subject: [PATCH 2/3] fix some moments --- src/arrayMethodJoin.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 9048b32a..fd824aab 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,19 +5,22 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator = ',') { - let resultString = ''; + let joinedString = ''; + let value = []; for (let i = 0; i < this.length; i++) { - if (this[i] !== null && this[i] !== undefined) { - resultString += this[i]; + value = this[i]; + + if (value !== null && value !== undefined) { + joinedString += value; } if (i !== this.length - 1) { - resultString += separator; + joinedString += separator; } } - return resultString; + return joinedString; }; } From d3cb436f4cd5a3fa6c27d9b0ac102cb9f5e87a21 Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 17 Aug 2023 22:34:05 +0300 Subject: [PATCH 3/3] some improvements --- src/arrayMethodJoin.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index fd824aab..bd986ebd 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -6,13 +6,12 @@ function applyCustomJoin() { [].__proto__.join2 = function(separator = ',') { let joinedString = ''; - let value = []; for (let i = 0; i < this.length; i++) { - value = this[i]; + const valueOfArray = this[i]; - if (value !== null && value !== undefined) { - joinedString += value; + if (valueOfArray !== null && valueOfArray !== undefined) { + joinedString += valueOfArray; } if (i !== this.length - 1) {