Show the first number in the list that is above four.
Acceptance criteria
- 1.#out should show 8.
JavaScript Tutorial · JavaScript Arrays
These 10 tasks go with the JavaScript Array find chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “JavaScript find returns the first element that passes a test, or undefined.” .
1.Find the first matchexercise · easy · 10 min
Show the first number in the list that is above four.
Passes when: #out should show 8.
2.Find an object by idexercise · easy · 10 min · practice plan
Find the user with id 2 and show their name.
Passes when: #out should show Grace.
3.Report no matchexercise · easy · 10 min · practice plan
Show the type of what find gives back when nothing matches.
Passes when: #out should show undefined.
4.Find a positionexercise · easy · 10 min · practice plan
Use findIndex to show where the letter b sits.
Passes when: #out should show 1.
5.Find the last matchexercise · medium · 10 min · practice plan
Use findLast to show the last number above four.
Passes when: #out should show 12.
6.Fix filter used instead of findbug fix · easy · 8 min
filter gives an array, but a single value is wanted.
Passes when: #out should show 8.
7.Fix the guard checking for nullbug fix · easy · 8 min · practice plan
find returns undefined when nothing matches, not null, so the guard never fires.
Passes when: #out should show no user.
8.Fix find used for a positionbug fix · easy · 8 min · practice plan
The index is wanted, not the value itself.
Passes when: #out should show 1.
9.Fix the loose id comparisonbug fix · easy · 8 min · practice plan
The wrong user is found because the condition compares the wrong property.
Passes when: #out should show Grace.
10.Fix first used instead of lastbug fix · easy · 8 min · practice plan
The last match is wanted, not the first.
Passes when: #out should show 12.
Between them these tasks cover find, findIndex and findLast.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.