Skip to content

Commit 02d61bc

Browse files
committed
Update
1 parent 11e34a3 commit 02d61bc

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

examples/function/fun1.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const bmi = (h, w) => {
2+
return w / (h*h)
3+
}
4+
5+
let h = 1.7
6+
let w = 60
7+
8+
let result = bmi(h, w)
9+
console.log(result)

examples/function/fun2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const bmi = (h, w) => {
2+
let result = []
3+
for (let i = 0; i < h.length; i++) {
4+
result.push(w[i] / (h[i] * h[i]))
5+
}
6+
return result
7+
}
8+
9+
let h = [1.7, 2, 1.6, 1.5]
10+
let w = [60, 100, 60, 45]
11+
12+
console.log(bmi(h, w))

examples/function/fun3.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const bmi = (h, w) => {
2+
return w / (h*h)
3+
}
4+
5+
let h = [1.7, 2, 1.6, 1.5]
6+
let w = [60, 100, 60, 45]
7+
let result = []
8+
9+
h.forEach(function(element, index) {
10+
let hi = element
11+
let wi = w[index]
12+
result.push(bmi(hi, wi))
13+
});
14+
// >> hi
15+
console.log(result)

examples/function/fun4.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const bmi = (h, w) => {
2+
return w / (h*h)
3+
}
4+
5+
let h = [1.7, 2, 1.6, 1.5]
6+
let w = [60, 100, 60, 45]
7+
8+
let result = h.map(function(element, index, array) {
9+
let hi = element
10+
let wi = w[index]
11+
return bmi(hi, wi)
12+
})
13+
14+
console.log(result)

0 commit comments

Comments
 (0)