-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-iterator-methods.js
65 lines (45 loc) · 1.71 KB
/
array-iterator-methods.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Objective:
Demonstrate your ability to use various array iterator methods
(forEach(), map(), filter(), find(), findIndex(), some(), every(), reduce())
to solve practical programming challenges.
Instructions:
Complete the tasks below using only the specified array iterator methods.
Submit your final outputs as specified for each task.
Tasks:
Task 1: Using forEach()
Start with the array:
let cities = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"];
Use forEach() to log each city name to the console in uppercase.
Submit the output format:
Log output of each city in uppercase (console statements).
Task 2: Transforming with map()
Start with the array:
let numbers = [1, 2, 3, 4, 5];
Use map() to create a new array where each number is squared.
Submit the new array.
Task 3: Filtering with filter()
Start with the array:
let scores = [85, 42, 90, 75, 30, 100];
Use filter() to create a new array containing only the scores greater than or equal to 80.
Submit the new array.
Task 4: Finding with find() and findIndex()
Start with the array:
let items = ["apple", "banana", "cherry", "date"];
Use find() to locate the first fruit with more than 5 letters.
Use findIndex() to find the index of that fruit.
Submit the results as an array:
[foundFruit, foundIndex]
Task 5: Checking Conditions with some() and every()
Start with the array:
let temperatures = [72, 85, 90, 95, 100];
Use some() to check if at least one temperature is above 95.
Use every() to check if all temperatures are above 50.
Submit the results as an array:
[someResult, everyResult]
Task 6: Reducing with reduce()
Start with the array:
let prices = [10, 20, 30, 40];
Use reduce() to calculate the total sum of all prices.
Submit the total sum.
*/