From edc07a430fa05bcc71168231d46bacc0622d50ec Mon Sep 17 00:00:00 2001 From: Patryk Date: Tue, 15 Aug 2023 15:58:19 +0200 Subject: [PATCH] Solution --- src/arrayMethodJoin.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..ba32a6ad 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,7 +5,24 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + let result = ''; + + if (separator === undefined) { + // eslint-disable-next-line no-param-reassign + separator = ','; + } + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + result += this[i]; + } + + if (i !== this.length - 1) { + result += separator; + } + } + + return result; }; }