From a3f4ca664f7883bcce24448ca3b9876f117a3902 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Thu, 30 Nov 2023 12:27:37 -0500 Subject: [PATCH] Added module example --- .gitignore | 1 + exo-recapitulatif/index.html | 6 ++++++ exo-recapitulatif/script.js | 11 +++++++++++ modules-examples/stats.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 .gitignore create mode 100644 exo-recapitulatif/index.html create mode 100644 exo-recapitulatif/script.js create mode 100644 modules-examples/stats.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/exo-recapitulatif/index.html b/exo-recapitulatif/index.html new file mode 100644 index 0000000..0545bb6 --- /dev/null +++ b/exo-recapitulatif/index.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/exo-recapitulatif/script.js b/exo-recapitulatif/script.js new file mode 100644 index 0000000..125bc46 --- /dev/null +++ b/exo-recapitulatif/script.js @@ -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); \ No newline at end of file diff --git a/modules-examples/stats.js b/modules-examples/stats.js new file mode 100644 index 0000000..81c07fb --- /dev/null +++ b/modules-examples/stats.js @@ -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)); +} \ No newline at end of file