Added module example

This commit is contained in:
didier amyot committed 2023-11-30 12:27:37 -05:00
commit a3f4ca664f
4 files changed
+46

No files matched your search

+1
View File
@@ -0,0 +1 @@
.idea
+6
View File
@@ -0,0 +1,6 @@
<!doctype html>
<body>
<script src="script.js" type="module"></script>
<button id="foo">boom</button>
</body>
+11
View File
@@ -0,0 +1,11 @@
export function toto(){
console.log("say toto");
}
export function hello(){
console.log("say hello");
}
document.querySelector('#foo').addEventListener('click', toto);
document.querySelector('#foo').addEventListener('click', hello);
+28
View File
@@ -0,0 +1,28 @@
export function average(lst){
if(lst.length < 1){
return NaN;
}
let sum = 0;
let n = 0;
for(const e of lst){
sum += e;
n += 1;
}
return sum / n;
}
export function std(lst){
if(lst.length < 1){
return NaN;
}
let sum = 0;
let sum2 = 0;
let n = 0;
for(const e of lst){
sum += e;
sum2 += e * e;
n += 1;
}
return Math.sqrt( sum2 / n - Math.pow(sum / n, 2));
}