From 66e8f9ccbd9d279dd4c09ad0a77620b5468ed43d Mon Sep 17 00:00:00 2001 From: Oleksii Andriushyn Date: Fri, 4 Aug 2023 00:05:15 +0300 Subject: [PATCH] Solution --- src/arrayMethodJoin.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c1..04fd14d9f 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,8 +4,22 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here + [].__proto__.join2 = function(separator = ',') { + let stringFromJoinedArray = ''; + + for (let i = 0; i < this.length; i++) { + const itemContent + = this[i] === null || this[i] === undefined + ? '' + : this[i]; + + stringFromJoinedArray + += i === 0 + ? itemContent + : `${separator}` + itemContent; + } + + return stringFromJoinedArray; }; }