From 6eb734934225f7d62171ddc5490c9b393504896a Mon Sep 17 00:00:00 2001 From: Artem Trofymovych Date: Mon, 31 Jul 2023 13:35:06 +0200 Subject: [PATCH] add task solution --- src/arrayMethodJoin.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c1..d258dce1c 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -5,8 +5,26 @@ */ function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + let result = ''; + + let sep = separator; + + if (sep === undefined) { + sep = ','; + } + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + result += this[i]; + } + + if (i !== this.length - 1) { + result += sep; + } + } + + return result; }; -} +}; module.exports = applyCustomJoin;