Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here’s one i’m really proud of, i crafted it when learning js a while back. Its a one liner that flattens arbitrarily nested array. Its recursive though, so i guess it has its limits. I remember commenting something along the lines of “dark magic functional prog” (thats how i found it a second ago in GH actually):

const flatten = arr => ((flat = [].concat(...arr)) => flat.some(Array.isArray) ? flatten(flat) : flat)()

Its simple, but i was - and still am - way to proud of it ;p



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: