diff --git a/package.json b/package.json index 6a002cce..5a1a8ed9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..c61fac8b 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -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; }; }