Skip to content

Commit

Permalink
stage-1
Browse files Browse the repository at this point in the history
  • Loading branch information
no4kar committed Aug 20, 2023
1 parent d04c9f0 commit 9ae93ff
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
'use strict';

/**
* Implement method join
*/
function applyCustomJoin() {
/**
* @param {string | undefined} separator
* @returns {string} */
[].__proto__.join2 = function(separator) {
// write code here
let inerSeparator;
let joined = '';
let temp = '';

if (this.length === 0) {
return joined;
}

switch (separator) {
case null:
inerSeparator = 'null';
break;

case undefined:
inerSeparator = ',';
break;

default:
inerSeparator = separator;
}

for (let i = 0, last = this.length - 1; ; i++) {
temp = this[i];

switch (temp) {
case null:
case undefined:
temp = '';
break;
case true:
temp = 'true';
break;
case false:
temp = 'false';
break;
case NaN:
temp = 'NaN';
break;
default:
break;
}

joined += temp;

if (i === last) {
break;
}

joined += inerSeparator;
}

return joined;
};
}

Expand Down

0 comments on commit 9ae93ff

Please sign in to comment.