Skip to content

Commit 1979df5

Browse files
committed
update codes ...
1 parent eddb144 commit 1979df5

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
data = [12,23,34,45,56,67,78,89,90]
11+
12+
// square of each element in the array
13+
14+
// map()
15+
16+
function square(x){
17+
return x*x
18+
}
19+
20+
//console.log(square(12))
21+
22+
console.log(data.map(square)) // array_name.map(user_defined_function)
23+
24+
25+
</script>
26+
27+
28+
</head>
29+
<body>
30+
31+
</body>
32+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
data = [12,23,34,45,56,67,78,89,90]
11+
12+
// filter()
13+
14+
function isEven(x){
15+
return x%2 == 0
16+
}
17+
18+
console.log(data.filter(isEven)) // array_name.filter(user_defined_function)
19+
20+
21+
function isGreaterThan50(x){
22+
return x > 50
23+
}
24+
25+
console.log(data.filter(isGreaterThan50)) // array_name.filter(user_defined_function)
26+
27+
28+
</script>
29+
30+
31+
32+
</head>
33+
<body>
34+
35+
</body>
36+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
// reduce()
11+
12+
data = [12,23,34,45,56,67,78,89,90]
13+
14+
function sum(x,y){
15+
return x+y
16+
}
17+
18+
console.log(data.reduce(sum)) // array_name.reduce(user_defined_function)
19+
20+
21+
22+
// for loop
23+
total = 0;
24+
for(let i=0; i<data.length; i++){
25+
total = total + data[i]
26+
}
27+
28+
console.log(total)
29+
30+
</script>
31+
32+
33+
</head>
34+
<body>
35+
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)