From 7e3f72e22762d5ed02bae67701a95a60ef32afbb Mon Sep 17 00:00:00 2001 From: Mykyta Vyskrebentsev Date: Mon, 14 Aug 2023 00:16:48 +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 3a62201c..081f4b36 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 stringArray = ''; + + for (let i = 0; i < this.length; i++) { + const arrayElement = this[i]; + + if (arrayElement !== undefined && arrayElement !== null) { + stringArray += arrayElement; + } + + if (i !== this.length - 1) { + stringArray += separator; + } + }; + + return stringArray; }; }