Created
March 9, 2023 19:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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