-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: master
Are you sure you want to change the base?
Develop #2715
Conversation
src/arrayMethodJoin.js
Outdated
// write code here | ||
[].__proto__.join2 = function(separator = ',') { | ||
const arrCopy = [ ...this ]; | ||
let ConcatenatedStr = ''; |
There was a problem hiding this comment.
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
src/arrayMethodJoin.js
Outdated
const arrCopy = [ ...this ]; | ||
let ConcatenatedStr = ''; | ||
|
||
if (arrCopy.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (arrCopy.length === 0) { | |
if (!arrCopy.length) { |
src/arrayMethodJoin.js
Outdated
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; |
There was a problem hiding this comment.
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
No description provided.