From 882926a09193385e78f637a8bf67e14458a583e4 Mon Sep 17 00:00:00 2001 From: Vitalii Popovych Date: Fri, 11 Aug 2023 21:13:18 -0500 Subject: [PATCH] Solution --- src/arrayMethodJoin.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..568d471c 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,8 +4,19 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { + [].__proto__.join2 = function(separator = ',') { // write code here + let resultString = ''; + + for (let i = 0; i < this.length; i++) { + if (typeof (this[i]) !== 'undefined' && this[i] !== null) { + resultString += `${this[i]}`; + } + + resultString += `${i < this.length - 1 ? separator : ''}`; + } + + return resultString; }; }