Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Created March 9, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinocarl/33999a3f6ecc9a18ffea18615aca5d32 to your computer and use it in GitHub Desktop.
Save dinocarl/33999a3f6ecc9a18ffea18615aca5d32 to your computer and use it in GitHub Desktop.
Given a list of objects and list of keys from them, find the longest length
const data = [
{ label: 'first', val: 'gold-like' },
{ label: 'second', val: 'silver-esque' },
{ label: 'third', val: 'bronz-ish' },
];
const propLen = (propName) => compose(
length,
propOr('', propName)
);
const maxList = reduce(max, 0);
const maxPropLen = (propList) => compose(
maxList,
juxt(map(propLen, propList))
);
const maxPropLenList = (propList) => compose(
maxList,
map(maxPropLen(propList))
);
const maxPropLenList2 = (propList) => reduce(
(acc, item) => max(
acc,
maxPropLen(propList)(item)
),
0
)
maxPropLenList2(['label', 'val'])(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment