Another F# one.
(But as I read it, the return value should be a string, not a list, and therefore a little input validation is needed to handle the input arrays being empty).
let stockByCategory(books: string) (cats: string): string =
if books = [||] || cats = [||] then
(fun cat -> books |> Seq.filter (fun book -> book.StartsWith cat)
|> Seq.sumBy(fun book -> book.Split(' '). |> int)
|> (sprintf "(%s : %d)" cat))
|> String.concat " - "
You're right about the requirements, should have been a string. 🤷♂️
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.