Skip to content

Commit c3c3848

Browse files
rms
Signed-off-by: Arnav Gupta <[email protected]>
1 parent 3024319 commit c3c3848

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let arr = [45, 312, 524, 7648, 324, 523, 535, 76, 45, 3, 2356]
2+
let arr0 = [45, -312, 524, 7648, -324, 523, 535, -76, 45, 3, -2356]
3+
4+
let x = function(v, i, a) {
5+
return v / i
6+
}
7+
8+
let arr2 = arr.map(x)
9+
10+
let y = function(v, i, a) {
11+
return v % 2 == 0
12+
}
13+
14+
let arr3 = arr.filter(y)
15+
16+
let sum = arr.reduce(function(accum, value, index, array) {
17+
console.log(accum, value, index)
18+
return accum + value
19+
})
20+
21+
let negSum = arr0.reduce(
22+
function(ac, val, i, a) {
23+
console.log(ac, val, i)
24+
if (val < 0) {
25+
ac += val
26+
}
27+
28+
return ac
29+
30+
},
31+
0,
32+
)
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script src="array-ops.js"></script>
9+
</head>
10+
<body>
11+
12+
<input style="width: 400px" id="vals">
13+
<button id="calc">Calculate</button>
14+
<table border="1" cellpadding="10">
15+
<tr>
16+
<td><sub>N</sub>rms</td>
17+
<td id="nRMS"></td>
18+
</tr>
19+
<tr>
20+
<td><sub>P</sub>rms</td>
21+
<td id="pRMS"></td>
22+
</tr>
23+
<tr>
24+
<td>rms</td>
25+
<td id="RMS"></td>
26+
</tr>
27+
</table>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)