From b99114e026c69295d61fb948ea680d37d3eb9b42 Mon Sep 17 00:00:00 2001 From: UlianaChorna <110450537+UlianaChorna@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:14:36 +0200 Subject: [PATCH] task solution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..35557402 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 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 += separator; + } + } + + return string; }; }