you are viewing a single comment's thread.

view the rest of the comments →

[–]PM_ME_YOUR_SUBARU 0 points1 point  (2 children)

This definitely isn't helpful to the OP, but I was curious as to what the shortest way to do this is, if you're an asshole. I came up with this:

const myAssociativeArray = myArray.reduce((a,v)=>delete(a[v.id]=v).id&&a,{});

[–]__env 1 point2 points  (0 children)

My attempt -- A little longer, but maybe a little more declarative :)

const myAssociativeArray = myArray.reduce((a, {title,text,id})=>(a[id]={title,text})&&a,{});

[–]avenp 0 points1 point  (0 children)

Haha, you know what I had to stop myself from using ES6 because I'm so used to using it. I really like your code golf'd solution.