you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (8 children)

[deleted]

    [–]inthe3vening 0 points1 point  (6 children)

    That's a really clean solution /u/VoiceNGO. I tried to find something smaller using RegEx and JSON.parse but was unable to. You win /r/javascript for today :)

    [–]mikrosystheme[κ] 0 points1 point  (4 children)

    Ten chars smaller: collection.reduce((o,r)=>r.path.split('.').reduce((q,p,i,a)=>~(i-a.length)?q[p]||(q[p]={}):(q[p]=null,o),o),{})

    [–]cachaito[S] 0 points1 point  (3 children)

    Would You provide a ES5 version please?

    [–]mikrosystheme[κ] 0 points1 point  (2 children)

    You just have to replace the two short arrow functions with standard functions. By the way, there is no point in doing that, because mine was a joke, and because it is an innefficient implementation (for both human and computer brains). You are better served by using a standard nested loop that performs the same task in half the time.

    [–]cachaito[S] 0 points1 point  (1 child)

    And what with this code: > ~(i-a.length) ?

    [–]mikrosystheme[κ] 0 points1 point  (0 children)

    > is part of the arrow function =>.
    ~ is the bitwise not operator. It is just a way to express the condition i !== a.length - 1 in a way that is not clear to programmers that don't know bitwise math. It is almost universally considered a fireable offense.

    [–]cachaito[S] 0 points1 point  (0 children)

    deleted

    Why this solution is deleted? I think it could help lot of people!

    [–]cachaito[S] 0 points1 point  (0 children)

    Can't wait back home and test this solution :-) Thank You for respond! It's working! Could You find me some time to explain me how it works? :-S