-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
47 lines (38 loc) · 831 Bytes
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod utils;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn factorialize(mut num: u32) -> u32 {
let mut result = num;
if num == 0 || num == 1 {
1;
}
while num > 1 {
num = num - 1;
result = result * num;
}
return result;
}
#[wasm_bindgen]
pub fn factorialize_fib(n: u32) -> u32 {
let mut a:u32 = 0;
let mut temp:u32 = 0;
let mut b:u32 = 1;
let mut i:u32 = 1;
while i < n {
a = temp;
temp = b;
b = a + temp;
factorialize(b);
i = i + 1;
}
return b;
}