Hi everyone!
I’m requesting a view of my solutions for the Test your skills: Arrays exercise.
CodePen Links:
Arrays 1
Arrays 2
Arrays 3
Arrays 4
Feedback is appreciated, thank you!
Hi everyone!
I’m requesting a view of my solutions for the Test your skills: Arrays exercise.
CodePen Links:
Arrays 1
Arrays 2
Arrays 3
Arrays 4
Feedback is appreciated, thank you!
Hi again @jt_1
Good work! Here are my comments:
const
on the loop item (for (const item of myArray) {}
). This also reminds us that item
is just a temporary variable inside the loop.itemIndex
) in the loop, but they are immediately discarded instead of replacing the existing elements in the loop. Hint: Assign the new element at the correct index of the array. It may be easier to use another type of loop like forEach() where you have access to the index
directly in the callback function.birds.slice(eagleIndex + 1)
doesn’t return the array without “Eagles” as asked in the first part of the task. Try console.log()
that part to see what you are returning. Hint: Have a look at splice().If my explanations are unclear, just ask.
See you,
Michael
Thank you @mikoMK!
I’ve re-worked 3 and 4 based on your feedback. I’ll be sure to implement the HTML, CSS as well in future posts!
Arrays 3 (new):
https://codepen.io/jt_1/pen/poqwooZ
Arrays 4 (new):
https://codepen.io/jt_1/pen/KKbqKKe
Using forEach
was a little intimidating at first because it’s not really covered in JavaScript First Steps but looks like the concept will be explained more in the JavaScript Building Blocks section. Anyway, I was able to get something working with it, yay!
Let me know your thoughts.
By the way - on the original solution for Arrays 4, I put .slice
but actually meant .splice
. Whoops lol.
I have no idea what .slice
does but when I tested it seemed to show the results needed. (Old solution for reference - https://codepen.io/jt_1/pen/BavpNRJ)
Regardless, I still like my new solution better on the 2nd attempt!
Neato! Great improvements.
By the way using filter()
in “Array 4” like you did in your first version was fine. But as usual with JS there are multiple ways to solve a problem.
Understandable. On the plus side there are several methods that operate on every elements of an array that are much easier to understand now that you know how forEach()
works. You already used filter()
and another one I frequently use is map()
.
Ok got it and thank you so much again for your helpful feedback on this!