Hi,
I have completed a test and I need a review for the code.
Here are my code pen link and task link
This is also correct!
If you like, here’s an additional question:
If you have to build a new array from an existing array with a certain condition, you can use Array.prototype.filter(). Can you rewrite your solution to use filter()
instead of a normal loop?
Cheers,
Michael
Cool, your suggestion saved me some lines and made the code look less clunky.
Here you can see it for yourself. Thank you so much for your insights, they help me a lot. Also, I know that you’re a busy man, so I request you to take as much time as you want to reply to my queries.
Thank you again dear Sir,
Dinesh
That was exactly what I meant. I like how clean the solution looks when using filter()
. There are more similar array methods. The most commonly used are probably:
- Array.prototype.forEach(): Loop through an array and directly use the element and the index inside the function
- Array.prototype.map(): Execute a function on every element and return a new array with the results
Appreciated! I’m trying to not let people wait too long, but sometimes it takes a few days. I’m really happy that so many learners are coming back with more tasks. It’s a good sign that my answers seem to be useful.
Michael