In this post, we will take a look at forms of for loop, array methods using which you can make your code simpler, more readable. These loops / me...
For further actions, you may consider blocking this person and/or reporting abuse
Great article! I noticed some minor bugs:
You can change
+=
to just be+
also.Same goes for:
Cheers!
Good catch :D thank you very much :)
Nice article!
If people are interested to read more on this style of programming in JS, it's called "functional programming". See this article for an introduction: dev.to/leandrotk_/functional-progr...
A really nice library for doing functional-style programming with JS: ramdajs
Nice article. Thanks, Kartik. By the way, there is a little note to mention. It's better to use (for in) for objects and (for of) for arrays. Because (for in) has been optimized for Objects and not arrays.
Oh cool, I didn't know that. Thanks for sharing :)
Nice article.
//sum of array elements
arr.reduce((accumulator, currentValue) => (acc += curr), 0)
should be:
//sum of array elements
arr.reduce((accumulator, currentValue) => (accumulator += currentValue), 0)
Changed it. Thank you :)
Awesome write up! I'm glad you mentioned the less known ones as well like some and every. An additional note on the "for of" and forEach regarding accessing the index of an element would be nice. If you're interested in continuing to write about working with Arrays, the spread, rest, destructuring, Array.from and using asynchronous calls within loops would be another welcome write up!
Yes these are interesting ideas will write about them soon :).
// checking if at least one of them is 18 or above
arr.some(val => val >= 18)
should be:
// checking if at least one of them is 18 or above
friends.some(val => val >= 18)
Good article, but next time you need to check the examples in the console men, you can do it better ;)
Hehe thanks. Did run the examples on console, changed the names later though hence the issue. Will be careful next time :)
I should have known about
array.every()
earlier than today. Would've saved me time and brainsThanks for the link it's a nice read to get into performant code :).