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

for (let i = 0; i < this.length; i++) {
const element = this[i];
const lastElement = i === this.length - 1;

/**
* wanted to use `joinedString += element ?? ''`,
* meaning without any `if()` construction,
* but mate's eslint unables me to do it
*/
if (element !== undefined && element !== null) {
joinedString += element;
}

if (!lastElement) {
joinedString += separator;
}

Choose a reason for hiding this comment

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

The current implementation uses nested if statements. According to the checklist, you should avoid nested if statements:

  1. [CODE STYLE] - avoid using nested if statements, we are sure that you can do it without them :)

}

return joinedString;
};
}

Expand Down