Skip to content

Commit

Permalink
previous solution
Browse files Browse the repository at this point in the history
  • Loading branch information
voievodik committed Aug 7, 2023
1 parent 9c8301e commit 38e9193
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator = ',') {
const STRING_SEPARATOR = String(separator);
let finalString = '';
let finalResult = '';

for (let i = 0; i < this.length; i++) {
const arrayElement = this[i];

if (arrayElement === undefined || arrayElement === null) {
finalString += STRING_SEPARATOR;
continue;
if (arrayElement !== null && arrayElement !== undefined) {
finalResult += arrayElement;
}

finalString += arrayElement + STRING_SEPARATOR;
if (i !== this.length - 1) {
finalResult += separator;
}
}

return finalString.slice(0, finalString.length - STRING_SEPARATOR.length);
return finalResult;
};
}

Expand Down

0 comments on commit 38e9193

Please sign in to comment.