-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap function.html
More file actions
55 lines (45 loc) · 1.16 KB
/
Copy pathmap function.html
File metadata and controls
55 lines (45 loc) · 1.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Understand JS - Custom Map</title>
<style>
body {
font-family: Arial;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
cursor: pointer;
}
#output {
margin-top: 20px;
font-size: 20px;
color: green;
}
</style>
</head>
<body>
<h1>Custom Map Function Demo</h1>
<p>Click the button to double numbers</p>
<button onclick="runMap()">Run</button>
<div id="output"></div>
<script>
// Your custom map function
function myMap(array, callback) {
let result = [];
for (let i = 0; i < array.length; i++) {
result.push(callback(array[i], i, array));
}
return result;
}
function runMap() {
const numbers = [1, 2, 3, 4];
const doubled = myMap(numbers, function(num) {
return num * 2;
});
document.getElementById("output").innerText = doubled.join(", ");
}
</script>
</body>
</html>