forked from freeCodeCamp/euler-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make socket location dynamic for Gitpod
- Loading branch information
1 parent
b2288a7
commit d991770
Showing
3 changed files
with
22 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,15 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
// Rust uses snake_case, but JS uses camelCase | ||
#[wasm_bindgen(js_name = multiplesOf3and5)] | ||
pub fn multiples_of_3_and_5(n: i32) -> i32 { | ||
let mut t = 0; | ||
for i in 0..n { | ||
if i % 3 == 0 || i % 5 == 0 { | ||
t += i; | ||
} | ||
} | ||
t | ||
} | ||
|
||
#[wasm_bindgen(js_name = fiboEvenSum)] | ||
pub fn fibo_even_sum(n: i32) -> i32 { | ||
if n <= 1 { | ||
return 0; | ||
} else { | ||
let mut even_sum = 0; | ||
let mut prev_fib_num = 1; | ||
let mut fib_num = 2; | ||
while fib_num <= n { | ||
if fib_num % 2 == 0 { | ||
even_sum += fib_num; | ||
} | ||
let temp = fib_num.clone(); | ||
fib_num = prev_fib_num + fib_num; | ||
prev_fib_num = temp; | ||
} | ||
return even_sum; | ||
} | ||
// Example format to write functions: | ||
#[wasm_bindgen(js_name = camelCaseName)] // js_name must equal function name tested on client | ||
pub fn snake_case_name(num: i32) -> i32 { // Function must be public | ||
// All numbers in JS are 32-bit | ||
num | ||
} | ||
|
||
#[wasm_bindgen(js_name = largestPrimeFactor)] | ||
pub fn largest_prime_factor(n: i32) -> i32 { | ||
// First function written for you - you still need to add the logic :) | ||
#[wasm_bindgen(js_name = multiplesOf3and5)] | ||
pub fn multiples_of_3_and_5(n: i32) -> i32 { | ||
n | ||
} | ||
|