In Rust – playground link (with tests)
pub fn dub_enc(inp: String) -> String { let lowered = inp.to_lowercase(); lowered .chars() .map(|c| { let mut finder = lowered.chars().filter(|r| *r == c); finder.next(); // exists if finder.next().is_some() { // found at least once more ")" } else { "(" } }) .collect() }
Why not use std::str::matches to iterate over the same chars?
I suppose that is a valid alternative. Just not the first thing that came to mind ...
I just love how Rust has a helpful method for about everything in its std/core libs.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Rust – playground link (with tests)
Why not use std::str::matches to iterate over the same chars?
I suppose that is a valid alternative. Just not the first thing that came to mind ...
I just love how Rust has a helpful method for about everything in its std/core libs.