Skip to content

Commit

Permalink
fix: make socket location dynamic for Gitpod
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunSHamilton committed Feb 23, 2022
1 parent b2288a7 commit d991770
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
6 changes: 5 additions & 1 deletion .freeCodeCamp/output/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");
const socket = new WebSocket(
`${window.location.protocol.includes("https") ? "wss" : "ws"}://${
window.location.host
}`
);

const handle = {
"toggle-loader-animation": toggleLoaderAnimation,
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ You can write all the functions within one file, and follow the pattern given fo

1. `Ctrl + Shift + P` and `freeCodeCamp: Run Course`
2. `npm run build` to compile the Rust code, before each test.

## WASM Specific

- Numbers in JS are only `i32` or `f32`

## Notes

- It can take a few minutes to install all the dependencies/tools, on first start. The terminal will tell you its progress.
41 changes: 9 additions & 32 deletions src/lib.rs
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
}

0 comments on commit d991770

Please sign in to comment.