Skip to content

Instantly share code, notes, and snippets.

@benjcal
Last active March 23, 2018 17:16
Show Gist options
  • Save benjcal/33630e0a7d26b30fb1fe7b353969591f to your computer and use it in GitHub Desktop.
Save benjcal/33630e0a7d26b30fb1fe7b353969591f to your computer and use it in GitHub Desktop.
JS - Rust comparison
let startArr = [1, 2, 3, 4, 5]
let newArr = startArr.filter(n => n > 2) // -> [3, 4, 5]
let newStr = "foo bar"
let result = newStr.startsWith("foo") // -> true
fn main() {
let start_vec = vec![1, 2, 3, 4, 5];
let new_vec: Vec<_> = start_vec.iter().filter(|&&n| { n > 2 }).collect();
// -> [3, 4, 5]
let new_str = "foo bar";
let result = new_str.starts_with("foo"); // -> true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment