Please provide me a sample code for reversing a string and check the input string is palindrome using rust and wasm
fn is_palindrome(input: &str) -> bool {
input == reverse(input)
}
fn reverse(input: &str) -> String {
input.chars().rev().collect()
}
1 Like
Doing this properly is hard. Find a crate.
Otherwise you'll hit problems like this, using the reverse
above:
3 Likes
Of course. The actual code should be tailored for the case at hand. For example: do you consider ëte a palindrome? What about German ae, oe and ue? Do you consider their reverse to be ea, eo and eu, or a, e and u? Or ä, ö and ü? Consider my answer to be a hint to build on to encode your specific requirements.
1 Like
this sounds like a literal homework question
If for some reason you need to do grapheme-cluster-aware string reversal in a no_std
environment, there's a crate for that too.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.