From 3879c37834f3dbc1d77a2098a9f0cd1cf9dd69a0 Mon Sep 17 00:00:00 2001 From: Anastasia Bernada Date: Mon, 4 Sep 2023 13:26:19 +0300 Subject: [PATCH] Solution --- src/arrayMethodJoin.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c1..82ce75680 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 str = ''; + + for (let i = 0; i <= this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + str += this[i]; + } + + if (i < this.length - 1) { + str += separator; + } + } + + return str; }; }