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
18 changes: 16 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
let stringArray = '';

Choose a reason for hiding this comment

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

Why do you use the word array in the title, but it is a string type?
Try to choose a more meaningful naming.


for (let i = 0; i < this.length; i++) {
const arrayElement = this[i];

Choose a reason for hiding this comment

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

Try to choose a more meaningful naming.


if (arrayElement !== undefined && arrayElement !== null) {
stringArray += arrayElement;
}

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

return stringArray;
};
}

Expand Down