getValues
getValues
(collection: KeyedCollection) => any[]
Return an array of the collection's values
getValues({ a: 1, b: 2 }) // is [1, 2]
getValues({ a: 1, b: 2 }) // is [1, 2]
getValues({ a: 1, b: 2 }) // is [1, 2]
getValues({ a: 1, b: 2 }) // is [1, 2]
Sometimes we need the values of a collection. Below, we have the most streamed shows per platform. Let's flatten their values to list them all.
const mostStreamedShows = { netflix: ['Untamed', 'Amy Bradly Is Missing', 'Sandman'], hulu: ['Bachelor in Paradise', 'Washington Black', 'Love Island'], } const getPopularShows = compose([getValues, flattenOnce]) const shows = getPopularShows(mostStreamedShows) console.log(shows) // is [ // Untamed, // Amy Bradly Is Missing, // Sandman, // Bachelor in Paradise, // Washington Black, // Love Island, // ]
type ShowsByPlatform = Record<string, string[]> const mostStreamedShows: ShowsByPlatform = { netflix: ['Untamed', 'Amy Bradly Is Missing', 'Sandman'], hulu: ['Bachelor in Paradise', 'Washington Black', 'Love Island'], } const getPopularShows = compose([ getValues<ShowsByPlatform>, flattenOnce<Array<string[]>>, ]) const shows = getPopularShows(mostStreamedShows) console.log(shows) // is [ // Untamed, // Amy Bradly Is Missing, // Sandman, // Bachelor in Paradise, // Washington Black, // Love Island, // ]
const mostStreamedShows = { netflix: [ 'Untamed', 'Amy Bradly Is Missing', 'Sandman', ], hulu: [ 'Bachelor in Paradise', 'Washington Black', 'Love Island', ], } const getPopularShows = compose([ getValues, flattenOnce, ]) const shows = getPopularShows(mostStreamedShows) console.log(shows) // is [ // Untamed, // Amy Bradly Is Missing, // Sandman, // Bachelor in Paradise, // Washington Black, // Love Island, // ]
type ShowsByPlatform = Record<string, string[]> const mostStreamedShows: ShowsByPlatform = { netflix: [ 'Untamed', 'Amy Bradly Is Missing', 'Sandman', ], hulu: [ 'Bachelor in Paradise', 'Washington Black', 'Love Island', ], } const getPopularShows = compose([ getValues<ShowsByPlatform>, flattenOnce<Array<string[]>>, ]) const shows = getPopularShows(mostStreamedShows) console.log(shows) // is [ // Untamed, // Amy Bradly Is Missing, // Sandman, // Bachelor in Paradise, // Washington Black, // Love Island, // ]