Skip to content

Commit

Permalink
Soultion for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-Leman committed Jul 31, 2023
1 parent d04c9f0 commit 2eb25cf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
let separatorValue = separator;

if (separatorValue === undefined) {
separatorValue = ',';
}

const arr = this;
let result = '';

if (arr.length === 0) {
return '';
}

for (const element of arr) {
const str = element === null
|| element === undefined ? '' : element.toString();

result += str;

if (arr.indexOf(element) < arr.length - 1) {
if (separatorValue === null) {
separatorValue = 'null';
}
result += separatorValue.toString();
}
}

return result;
};
}

Expand Down

0 comments on commit 2eb25cf

Please sign in to comment.