-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas17.js
More file actions
60 lines (42 loc) · 1.29 KB
/
as17.js
File metadata and controls
60 lines (42 loc) · 1.29 KB
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
// 1. Create a function to iterate over the following list [“John”,
// “Rohn”, “Danny”, “James”]
// function iterate(){
// arr = ["John","Rohn", "Danny", "James"]
// for(let i of arr){
// console.log(i);
// }
// }
// iterate()
// 2. Iterate over all the characters of the word “iNeuron”.
// function iterate1(){
// str = "iNeuron"
// for(let i of str){
// console.log(i);
// }
// }
// iterate1()
// 3. Create a functional iterator, with a next function.
// not understand question
// 4. In the following two arrays find which two elements match
// using iterators.
// Array 1 - [“a”, “b”, “c”, “d”]
// Array 2 - [“e”, “f”, “g”, “h”, “a”, “i”, “j”]
// const array1 = ["a", "b", "c", "d"];
// const array2 = ["e", "f", "g", "h", "a", "i", "j"];
// for (const element1 of array1) {
// for (const element2 of array2) {
// if (element1 === element2) {
// console.log(`Match found: ${element1}`);
// }
// }
// }
// 5. What are the different ways of iterating through an array?
// demonstrate them.
// some common methods for iterating through an array in JavaScript:
// for loop
// forEach() method
// map() method
// filter() method
// reduce() method
// for-of loop
// for-in loop