From 7bf176647b0b6254139184c6ce1fcdcdef5627a2 Mon Sep 17 00:00:00 2001 From: Andrii Chornyi Date: Fri, 15 Sep 2023 13:29:08 +0300 Subject: [PATCH] add task solution --- src/arrayMethodJoin.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..53c19827 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -3,9 +3,30 @@ /** * Implement method join */ + function applyCustomJoin() { [].__proto__.join2 = function(separator) { - // write code here + const { sep } = { sep: separator === undefined ? ',' : String(separator) }; + + let result = ''; + + for (let i = 0; i < this.length; i++) { + if (i > 0) { + result += sep; + } + + if (this[i] === null || this[i] === undefined) { + result += ''; + } else { + if (String(this[i]) === 'null') { + result += 'null'; + } else { + result += String(this[i]); + } + } + } + + return result; }; }