Comment

Comment by llambda

I hate to be the bearer of bad news, but I think there may be even simpler solutions to this problem:

    (take 10 (reverse (sort-by (comp first rest) (frequencies (string/split ... #"\+s"))))

The above is a Clojure one-liner example that I believe satisfies the original problem. So while LINQ may have simplified from the C-language family solutions he had seen, it's clearly possible to take it one step further with the expressivity of modern languages like Clojure...

Edit: remember to sort! (Forgot my coffee this morning...)

Edit again: and aphyr's solution is even more concise and idiomatic, where `s` is the first paragraph of the blog post:

    => (->> (string/split s #"\s+") frequencies (sort-by val) reverse (take 10))
    (["I" 7] ["to" 6] ["the" 5] ["a" 5] ["of" 4] ["candidates" 3] ["is" 3] ["question" 3] ["in" 3] ["their" 2])
parent llambda 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton