From cb3658c656680fea9c347d22b9830922c17da78a Mon Sep 17 00:00:00 2001 From: Yaroslav220890 <126674531+Yaroslav220890@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:17:41 +0200 Subject: [PATCH] solution --- src/arrayMethodJoin.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..4beb322c 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -3,9 +3,22 @@ /** * Implement method join */ + function applyCustomJoin() { - [].__proto__.join2 = function(separator) { - // write code here + [].__proto__.join2 = function(separator = ',') { + let string = ''; + + for (let i = 0; i < this.length; i++) { + if (this[i] !== null && this[i] !== undefined) { + string += this[i]; + } + + if (i !== this.length - 1) { + string += separator; + } + } + + return string; }; }