From 70b02837668c4b93ba18dff85585b5574696b466 Mon Sep 17 00:00:00 2001 From: shikoryak Date: Fri, 25 Aug 2023 18:58:09 +0300 Subject: [PATCH 1/4] added solution task --- src/arrayMethodJoin.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..97ac995c 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,7 +5,16 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + let result = ''; + const readySeparator = separator !== undefined ? String(separator) : ','; + + for (let i = 0; i < this.length; i++) { + const value = this[i] === undefined || this[i] === null ? '' : this[i]; + + result += i === 0 ? value : readySeparator + value; + } + + return result; }; } From 1dafafcd17d8d7df9f0003d21a6c94d48d14f5dd Mon Sep 17 00:00:00 2001 From: shikoryak Date: Mon, 4 Sep 2023 11:43:09 +0300 Subject: [PATCH 2/4] resolved comment --- src/arrayMethodJoin.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 97ac995c..ef132c20 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -9,9 +9,17 @@ function applyCustomJoin() { const readySeparator = separator !== undefined ? String(separator) : ','; for (let i = 0; i < this.length; i++) { - const value = this[i] === undefined || this[i] === null ? '' : this[i]; + let value = this[i]; - result += i === 0 ? value : readySeparator + value; + if (value === undefined || value === null) { + value = ''; + } + + if (i === 0) { + result += value; + } else { + result += readySeparator + value; + } } return result; From 728fd231edb451ba8865184837229b957fdbdf32 Mon Sep 17 00:00:00 2001 From: shikoryak Date: Mon, 4 Sep 2023 11:56:07 +0300 Subject: [PATCH 3/4] fixed the code --- src/arrayMethodJoin.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index ef132c20..29f2124e 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -9,16 +9,14 @@ function applyCustomJoin() { const readySeparator = separator !== undefined ? String(separator) : ','; for (let i = 0; i < this.length; i++) { - let value = this[i]; + const value = this[i]; - if (value === undefined || value === null) { - value = ''; + if (value !== undefined && value !== null) { + result += value; } - if (i === 0) { - result += value; - } else { - result += readySeparator + value; + if (i !== this.length - 1) { + result += readySeparator; } } From 3243be6fec75b38800f3fddc10e247f678517fd1 Mon Sep 17 00:00:00 2001 From: shikoryak Date: Mon, 4 Sep 2023 15:31:48 +0300 Subject: [PATCH 4/4] some change --- src/arrayMethodJoin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 29f2124e..57048746 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,7 +4,7 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { + [].__proto__.join2 = function(separator = ',') { let result = ''; const readySeparator = separator !== undefined ? String(separator) : ',';