JavaScript puzzle oneliner - get unique values from list

Jan Küster - Dec 6 '22 - - Dev Community

Given the following datastructure:

const data = [{ foo: 'bar' }, { bar: 'baz' }, { foo: 'bar'}, { foo: 'baz'}, { foo: 'moo'}, { moo: 'bar'}, { foo: 'moo'}, { baz: 'moo' }, { foo: 'meh'}]
Enter fullscreen mode Exit fullscreen mode

Write a function getFoo that extracts all unique values for foo, except undefined. The overall code should be in one line using less than 60 characters.

Signature: object[] => string[]

No further conventions / restrictions. Think out of the box and not in clean code! Esoteric solutions welcomed!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player