Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
/**
* Implement method join
*/

function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
const { sep } = { sep: separator === undefined ? ',' : String(separator) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const sep = separator === undefined ? ',' : String(separator);


let result = '';

for (let i = 0; i < this.length; i++) {
if (i > 0) {
result += sep;
}

if (this[i] === null || this[i] === undefined) {
result += '';
} else {
if (String(this[i]) === 'null') {
result += 'null';
} else {
Comment on lines +21 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (String(this[i]) === 'null') {
          result += 'null';
        } else {

You can delete these lines of code

result += String(this[i]);
}
}
}

return result;
};
}

Expand Down