Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #2682

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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: 21 additions & 2 deletions src/arrayMethodJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@
* Implement method join
*/
function applyCustomJoin() {
[].__proto__.join2 = function(separator) {
// write code here
[].__proto__.join2 = function(separator = ',') {
const joinSeparator = String(separator);

Choose a reason for hiding this comment

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

Do we really need this?
I guess result will be the same with and without String()
image

Copy link

Choose a reason for hiding this comment

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

@AndrMar1939 reply to it

let resultingString = '';

this.forEach((item, index) => {
Copy link

Choose a reason for hiding this comment

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

Using Array methods is prohibited in this task. Use loops, index access, and array length if needed.

let stringCharacter = item;

if (item === null || item === undefined) {
stringCharacter = '';
}

if (this.length - 1 === index) {
resultingString += stringCharacter;

return;
}

resultingString += stringCharacter + joinSeparator;
});

return resultingString;
};
}

Expand Down
Loading