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

Develop #2715

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

vladyslav-svorin
Copy link

No description provided.

// write code here
[].__proto__.join2 = function(separator = ',') {
const arrCopy = [ ...this ];
let ConcatenatedStr = '';

Choose a reason for hiding this comment

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

variables name should be in a camelCase

const arrCopy = [ ...this ];
let ConcatenatedStr = '';

if (arrCopy.length === 0) {

Choose a reason for hiding this comment

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

Suggested change
if (arrCopy.length === 0) {
if (!arrCopy.length) {

Comment on lines 8 to 33
const arrCopy = [ ...this ];
let concatenatedStr = '';

if (!arrCopy.length) {
return '';
}

for (let i = 0; i < arrCopy.length; i++) {
if (arrCopy[i] === undefined || arrCopy[i] === null) {
arrCopy[i] = '';
}
}

for (let i = 0; i < arrCopy.length - 1; i++) {
arrCopy[i] += separator;

if (separator === null) {
arrCopy[i] += 'null';
}

concatenatedStr += arrCopy[i];
}

concatenatedStr += arrCopy[arrCopy.length - 1];

return concatenatedStr;

Choose a reason for hiding this comment

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

we can simplify this logic using only one loop and without copy the array
think about how to implement it and feel free to ask in the chat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants