Added module example
This commit is contained in:
commit
a3f4ca664f
4 files changed
+46
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
.idea
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<!doctype html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script src="script.js" type="module"></script>
|
||||||
|
<button id="foo">boom</button>
|
||||||
|
</body>
|
||||||
@@ -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);
|
||||||
@@ -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));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user