Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejKujawa committed Jul 31, 2023
1 parent d04c9f0 commit 5f84f78
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
let joinedArray = '';

for (let i = 0; i < this.length; i++) {
if (this[i] !== null && this[i] !== undefined) {
joinedArray += this[i];
}

if (i !== this.length - 1) {
joinedArray += separator;
}
}

return joinedArray;
};
}

Expand Down

0 comments on commit 5f84f78

Please sign in to comment.