getCommonValues
getCommonValues
(anArray: ValueCollection[]) => array
Return the values found in all collections
const result = getCommonValues([ ['a', 'b', 'c'], ['b', 'c', 'd'], ]) console.log(result) // is ['b', 'c']
const result = getCommonValues([ ['a', 'b', 'c'], ['b', 'c', 'd'], ]) console.log(result) // is ['b', 'c']
const result = getCommonValues([ ['a', 'b', 'c'], ['b', 'c', 'd'], ]) console.log(result) // is ['b', 'c']
const result = getCommonValues([ ['a', 'b', 'c'], ['b', 'c', 'd'], ]) console.log(result) // is ['b', 'c']
Sometimes we have a list of grouped values and want those found in all the groups. Below, we want to schedule a morning meeting with Liz, Phil, and Mary. Using their available hours, let's find potential meeting times.
const hoursAvailable = { liz: [7, 8, 9, 10], phil: [7, 9, 10, 11], mary: [8, 9, 10], } const getPotentialMeetingTimes = compose([Object.values, getCommonValues]) const potentialMeetingTimes = getPotentialMeetingTimes(hoursAvailable) console.log(potentialMeetingTimes) // is [ // 9, // 10, // ]
type HoursAvailable = Record<string, number[]> const hoursAvailable = { liz: [7, 8, 9, 10], phil: [7, 9, 10, 11], mary: [8, 9, 10], } const getPotentialMeetingTimes = compose([ getValues<HoursAvailable>, getCommonValues<number>, ]) const potentialMeetingTimes = getPotentialMeetingTimes(hoursAvailable) console.log(potentialMeetingTimes) // is [ // 9, // 10, // ]
const hoursAvailable = { liz: [7, 8, 9, 10], phil: [7, 9, 10, 11], mary: [8, 9, 10], } const getPotentialMeetingTimes = compose([ Object.values, getCommonValues, ]) const potentialMeetingTimes = getPotentialMeetingTimes(hoursAvailable) console.log(potentialMeetingTimes) // is [ // 9, // 10, // ]
type HoursAvailable = Record<string, number[]> const hoursAvailable = { liz: [7, 8, 9, 10], phil: [7, 9, 10, 11], mary: [8, 9, 10], } const getPotentialMeetingTimes = compose([ getValues<HoursAvailable>, getCommonValues<number>, ]) const potentialMeetingTimes = getPotentialMeetingTimes(hoursAvailable) console.log(potentialMeetingTimes) // is [ // 9, // 10, // ]