From 815a5b568bc926dc51cc142d7dcc536409581a26 Mon Sep 17 00:00:00 2001 From: Anna Kovnatska Date: Sun, 17 Sep 2023 18:31:57 -0500 Subject: [PATCH 1/2] array method join --- src/arrayMethodJoin.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..8d9ae292 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -6,6 +6,19 @@ function applyCustomJoin() { [].__proto__.join2 = function(separator) { // write code here + let result = ''; + + 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; }; } From 3df6b5b3c105fef4ff9ed08b5c8bb47c064fba38 Mon Sep 17 00:00:00 2001 From: Anna Kovnatska Date: Sun, 17 Sep 2023 18:34:40 -0500 Subject: [PATCH 2/2] array method join2 --- src/arrayMethodJoin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 8d9ae292..56dfd824 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -4,7 +4,7 @@ * Implement method join */ function applyCustomJoin() { - [].__proto__.join2 = function(separator) { + [].__proto__.join2 = function(separator = ',') { // write code here let result = '';