From a138b1d0539bcd051f49e75f7a8292791829db9e Mon Sep 17 00:00:00 2001 From: Kriss Kozak Date: Tue, 15 Aug 2023 17:58:28 +0300 Subject: [PATCH 1/3] method join --- src/arrayMethodJoin.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..da408497 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,8 +5,17 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + let result = ''; + + for (let i = 0; i < this.length; i++) { + if (i !== 0 && separator !== undefined) { + result += separator; + } + result += this[i]; + } + + return result; }; -} +}; module.exports = applyCustomJoin; From 909d09116e6d95131fc0bd69659cdf1c3c441d42 Mon Sep 17 00:00:00 2001 From: Kriss Kozak Date: Wed, 16 Aug 2023 11:08:17 +0300 Subject: [PATCH 2/3] method join() --- src/arrayMethodJoin.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index da408497..f41ce52e 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,17 +5,30 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { + let separator1 = separator; + + if (separator1 === undefined) { + separator1 = ','; + } + let result = ''; for (let i = 0; i < this.length; i++) { - if (i !== 0 && separator !== undefined) { - result += separator; + if (this[i] === null || this[i] === undefined) { + if (i !== this.length - 1) { + result += separator1; + } + } else { + result += this[i]; + + if (i !== this.length - 1) { + result += separator1; + } } - result += this[i]; } return result; }; -}; +} module.exports = applyCustomJoin; From 282f09238f9b985dd6a4f2afbc617be4a2993ef7 Mon Sep 17 00:00:00 2001 From: Krissy <120744713+Q1W2E3R4T5Y6U7I8a@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:16:34 +0300 Subject: [PATCH 3/3] Delete arrayMethodJoin.js --- src/arrayMethodJoin.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/arrayMethodJoin.js diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js deleted file mode 100644 index f41ce52e..00000000 --- a/src/arrayMethodJoin.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -/** - * Implement method join - */ -function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - let separator1 = separator; - - if (separator1 === undefined) { - separator1 = ','; - } - - let result = ''; - - for (let i = 0; i < this.length; i++) { - if (this[i] === null || this[i] === undefined) { - if (i !== this.length - 1) { - result += separator1; - } - } else { - result += this[i]; - - if (i !== this.length - 1) { - result += separator1; - } - } - } - - return result; - }; -} - -module.exports = applyCustomJoin;