Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^0.9.7",
"@mate-academy/scripts": "^1.2.12",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
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;
}
}

return joinedString;
};
}

Expand Down