Complete the code to sort the vector in ascending order.
let mut numbers = vec![5, 3, 8, 1]; numbers.[1]();
The sort() method sorts the vector in ascending order.
Complete the code to find if the number 4 exists in the sorted vector using binary search.
let numbers = vec![1, 3, 5, 7, 9]; let result = numbers.binary_search(&[1]);
Binary search looks for the value 4 in the sorted vector.
Fix the error in the code to sort a vector of strings alphabetically.
let mut words = vec!["pear", "apple", "orange"]; words.[1]();
The sort() method sorts strings alphabetically in place.
Fill both blanks to create a vector of squares for numbers greater than 3.
let numbers = vec![1, 2, 3, 4, 5]; let squares: Vec<_> = numbers.iter().filter(|&&x| x [1] 3).map(|&x| x[2]x).collect();
Filter numbers greater than 3 and square them using multiplication.
Fill both blanks to create a dictionary mapping words to their lengths for words longer than 4 characters.
let words = vec!["tree", "house", "car", "elephant"]; let word_lengths: std::collections::HashMap<_, _> = words.iter().filter(|&&word| word.len() [1] 4).map(|&word| (word[2], word.len(),)).collect();
Filter words longer than 4, convert word to String, and map to (word, length) pairs separated by a comma.
