Assessment wanted for Arrays tasks

Hello! Need assessment for Arrays skill tests.

Codepen:
Task 1.
Task 2.
Task 3.
Task 4.

Congratulations @VladimirK. Everything is correct :smiley:

Bonus question (if you like):
In task 4 instead of using a loop you could also filter the array. That’s an elegant way to create a new array based on a condition. Do you know how that could be achieved?

Happy coding,
Michael

2 Likes

Thank you @mikoMK!

I dont know but from the demo code i think that is something like this:

const eBirds = birds.filter(namesWithE => namesWithE.startsWith(‘E’));

or

const eBirds = birds.filter(function nameWithE(birds) {return birds.startsWith(‘E’)});

I will study it in more detail :relieved:

1 Like

Yes, both versions are correct.

You used namesWithE and birds as parameter names in the filter function. I would rename them to just bird as we are checking a single bird for the condition inside the function. For example: bird => bird.startsWith('E').
In the second version the traditional function doesn’t need a name. We can just write: function (bird) {...}

Those functions that operate on every element of an array are often a simpler way to achieve the same as a loop does. Other similar functions are:

Have a nice day,
Michael

1 Like