Coding challenge ( rust)

Give it a try and see if you can predict the output of this Rust program.
use std::collections::HashMap;

fn main() {
let input_numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

let result: Vec<_> = input_numbers
.iter()
.filter(|&&x| x % 2 == 0)
.map(|x| x * x)
.filter(|&x| x > 20)
.fold(HashMap::new(), |mut acc, x| {
let counter = acc.entry(x % 5).or_insert(0);
*counter += 1;
acc
})
.into_iter()
.filter(|&(_, count)| count > 1)
.map(|(key, _)| key)
.collect();

println!("{:?}", result);
}
use std::collections::HashMap;

fn main() {
let input_numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

let result: Vec<_> = input_numbers
.iter()
.filter(|&&x| x % 2 == 0)
.map(|x| x * x)
.filter(|&x| x > 20)
.fold(HashMap::new(), |mut acc, x| {
let counter = acc.entry(x % 5).or_insert(0);
*counter += 1;
acc
})
.into_iter()
.filter(|&(_, count)| count > 1)
.map(|(key, _)| key)
.collect();

println!("{:?}", result);
}
4 Replies
Aditya thakekar
Aditya thakekar10mo ago
Feels like something is missing
nour_oud
nour_oudOP10mo ago
Nope, just a trap 😆
Aditya thakekar
Aditya thakekar10mo ago
Empty array 😏😏😏
nour_oud
nour_oudOP10mo ago
Yup 🙌 , what about the steps ?
Want results from more Discord servers?
Add your server