Browse Source

Added README.md

Luiserebii 2 years ago
parent
commit
ef68a8e96f
Signed by: Luiserebii <luis@serebii.io> GPG Key ID: 58A745E0A5422230
3 changed files with 5 additions and 62 deletions
  1. 5
    0
      README.md
  2. 0
    62
      math.js
  3. BIN
      routes/.api_v1.js.swp

+ 5
- 0
README.md View File

@@ -0,0 +1,5 @@
1
+# MathFun Express Server
2
+A fun mini-project in Express. Currently implements two fibonacci functions and returns results in JSON.
3
+
4
+This is currently hosted at: http://serebii.io:3000/
5
+Example query: http://serebii.io:3000/v1/fibonacci?n=10

+ 0
- 62
math.js View File

@@ -1,62 +0,0 @@
1
-/*
2
- * ===========================
3
- *  Math module for fun stuff
4
- * =========================== 
5
- * 
6
- * Current functions implemented:
7
- *    -Fibonacci
8
- *
9
- */
10
-
11
-class MathFun {
12
-
13
-
14
-   //0 1 1 2 3 5....
15
-   //If the number exists within the fibonacci series, return true
16
-   //Otherwise, is false
17
-   static isFibonacci(num){
18
-      let a = 0;
19
-      let b = 1;
20
-      let next = a + b;
21
-
22
-      //Check initial values beforehand to get these out of the way...
23
-      //TODO: Arguable inefficiency here in checking 1 twice, both here and in the loop
24
-      if(num == a || num == b) { return true; } 
25
-
26
-      while(next <= num){
27
-         next = a + b;
28
-         a = b;
29
-         b = next;
30
-
31
-         if(next === num){
32
-            return true;
33
-         }
34
-      }
35
-
36
-      return false;
37
-
38
-   }
39
-
40
-   //Returns the nth fibonacci number
41
-   static fibonacci(n){
42
-      let a = 0;
43
-      let b = 1;
44
-      let next = a + b;
45
-
46
-      //Check if we're looking for the first 2 in the series
47
-      if(n == 1){ return a; } else if(n == 2) { return b; }
48
-
49
-      for(var i = 2; i < n; i++){
50
-         next = a + b;       
51
-         a = b;
52
-         b = next;
53
-      }
54
-
55
-      return b; //b represents the current one, so let's return this
56
-   }  
57
-
58
-
59
-}
60
-
61
-
62
-module.exports = MathFun;

BIN
routes/.api_v1.js.swp View File


Loading…
Cancel
Save