Home > Javascript > lodash-fp 2

lodash-fp 2

reduce array/collection   Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of collection is used as the initial value.
       

 

import reduce from ‘lodash/fp/reduce’

const noCapReduce=reduce.convert({ ‘cap’: false })

const red = noCapReduce((result,value,key)=>{

    ((result[value])||(result[value]=[])).push(key)

return result;

},{})

console.log(red({ jey11: 1, jey23: 3, jey223: 3 }))

Advertisements
Categories: Javascript Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: