Problems

Group by First Letter

MediumArrays & Objects

Read a JSON array of lowercase words. Group them by first letter into an object whose keys appear in alphabetical order, and print it as JSON.

Input: one JSON array of words. Output: JSON object: letter → array of words (original order within groups, keys sorted).

Your program reads from stdin and prints to stdout.

Example 1

Input: ["apple","banana","avocado","cherry"]

Output: {"a":["apple","avocado"],"b":["banana"],"c":["cherry"]}

Hints

JavaScriptObjectsreduce