Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoria-roik committed Aug 4, 2023
1 parent d04c9f0 commit 90cd115
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
const arrLength = this.length;
let joinedString = '';

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

if (i !== arrLength - 1) {
joinedString += separator;
}
}

return joinedString;
};
}

Expand Down

0 comments on commit 90cd115

Please sign in to comment.