Skip to content

Commit d161d72

Browse files
committed
src/bin/count-items-matching-a-rule.rs
1 parent 78e511a commit d161d72

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: src/bin/count-items-matching-a-rule.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(dead_code, unused, unused_variables, non_snake_case)]
2+
3+
fn main() {}
4+
5+
struct Solution;
6+
7+
impl Solution {
8+
pub fn count_matches(items: Vec<Vec<String>>, rule_key: String, rule_value: String) -> i32 {
9+
items
10+
.into_iter()
11+
.filter(|x| match rule_key.as_str() {
12+
"type" => x[0] == rule_value,
13+
"color" => x[1] == rule_value,
14+
"name" => x[2] == rule_value,
15+
_ => unreachable!(),
16+
})
17+
.count() as i32
18+
}
19+
}

0 commit comments

Comments
 (0)