From 70403b992b528df3c8c7caa4b8cbeb29a4851bac Mon Sep 17 00:00:00 2001 From: Annbpiu Date: Sun, 20 Aug 2023 18:34:19 +0300 Subject: [PATCH 1/2] complete the tusk --- src/arrayMethodJoin.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..eb1814d0 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,7 +5,29 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + if (this.length === 0) { + return ''; + } + + let finalSeparator = separator; + + if (separator === undefined) { + finalSeparator = ','; + } + + 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 += finalSeparator; + } + } + + return string; }; } From 142c1a7f3bdb38b5a80e7fa249aa9756c54027ba Mon Sep 17 00:00:00 2001 From: Annbpiu Date: Mon, 21 Aug 2023 12:50:19 +0300 Subject: [PATCH 2/2] fix --- src/arrayMethodJoin.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index eb1814d0..35557402 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,17 +4,7 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - if (this.length === 0) { - return ''; - } - - let finalSeparator = separator; - - if (separator === undefined) { - finalSeparator = ','; - } - + [].__proto__.join2 = function(separator = ',') { let string = ''; for (let i = 0; i < this.length; i++) { @@ -23,7 +13,7 @@ function applyCustomJoin() { } if (i !== this.length - 1) { - string += finalSeparator; + string += separator; } }