From eaf3aa7346f95ee7a0411d0649c037c48784605d Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Sat, 12 Aug 2023 17:27:40 +0300 Subject: [PATCH 1/2] solution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..51fb89c7 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 result = ''; + + for (let i = 0; i < this.length; i++) { + if (typeof (this[i]) !== 'undefined' && this[i] !== null) { + result += this[i]; + } + + if (i !== this.length - 1) { + result += separator; + } + } + + return result; }; } From d276f4d228050539ad217c910276e9accf8d8ee5 Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Sun, 13 Aug 2023 15:16:13 +0300 Subject: [PATCH 2/2] fixed problem --- src/arrayMethodJoin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 51fb89c7..060e47ea 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -8,7 +8,7 @@ function applyCustomJoin() { let result = ''; for (let i = 0; i < this.length; i++) { - if (typeof (this[i]) !== 'undefined' && this[i] !== null) { + if (this[i] !== undefined && this[i] !== null) { result += this[i]; }