How might I find the number of occurrences of elements in a list in ReasonML? I'm not exactly sure how to attempt this. Thank you!
Asked
Active
Viewed 98 times
-6
-
I feel like I've stumbled on a large oddity here. What's the reason for all the gibberish? It only makes me more curious to check the edit history, and see that your question was very simple/not spam/not a bad question or in need of deleting/etc. Was your account hacked? [NB: See the edit history for context on this and the next comments] – i336_ Jan 04 '20 at 22:55
-
4Please don't make more work for others by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under a [CC BY-SA license](//creativecommons.org/licenses/by-sa/4.0), for SE to distribute the content (i.e. regardless of your future choices). By SE policy, the non-vandalized version is distributed. Thus, any vandalism will be reverted. Please see: [How does deleting work? …](//meta.stackexchange.com/q/5221). If permitted to delete, there's a "delete" button below the post, on the left, but it's only in browsers, not the mobile app. – Makyen Jan 04 '20 at 22:56
1 Answers
2
This sounds like an exercise, so I won't just give you the answer, but you can do this either using just List.fold_left
if you're familiar with and allowed to use it, or by writing you own recursive function to traverse the list. They should both turn out very simple.
With either method, for each element encountered, add 1
to the result of counting the rest of the list if it matches, or just return the count for the rest of the list if it doesn't.

glennsl
- 28,186
- 12
- 57
- 75