Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I map over object values using Ramda.js and take only first element?

I have input like that:

{
  a: [obj1, obj2, obj3...],
  b: [obj1, obj2, obj3...],
  c: [obj1, obj2, obj3...]
}

I want to have that output (only first object from array for every key)

{
  a: [obj1],
  b: [obj1],
  c: [obj1]
}

I want to do it using ramda.js

like image 925
John Taylor Avatar asked Dec 08 '22 17:12

John Taylor


1 Answers

The simplest answer is just map(head, obj), or if you want a reusable function, map(head).

You can see this in action on the Ramda REPL.

like image 179
Scott Sauyet Avatar answered Dec 10 '22 06:12

Scott Sauyet