From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/js/jestBasic/fibo.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 graphs/js/jestBasic/fibo.js (limited to 'graphs/js/jestBasic/fibo.js') diff --git a/graphs/js/jestBasic/fibo.js b/graphs/js/jestBasic/fibo.js new file mode 100644 index 0000000..0a19955 --- /dev/null +++ b/graphs/js/jestBasic/fibo.js @@ -0,0 +1,29 @@ +function fibo(n) { + if (typeof n != "number" || isNaN(n)) { + return -1; + } + + if (n < 0) { + return -1; + } + + if (n === 0) { + return 0; + } + + let a = 1; + let b = 1; + let result = 1; + + for (let i = 2; i < n; i++) { + result = a + b; + b = a; + a = result; + } + + return result; +} + +module.exports = { + fibo, +}; -- cgit v1.2.3