From 068e795a0946596791977a77a3a150a4cfcd5c06 Mon Sep 17 00:00:00 2001 From: kyrylomanko Date: Mon, 21 Aug 2023 13:53:31 +0200 Subject: [PATCH] Solution added --- src/arrayMethodJoin.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..4252f8d0 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,9 +4,20 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here + [].__proto__.join2 = function(separator = ',') { + let str = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== undefined && this[i] !== null) { + str += this[i]; + } + + if (i !== this.length - 1) { + str += separator; + } + } + + return str; }; } - module.exports = applyCustomJoin;