DEV Community


Discussion on: The case for replacing Array.slice

herteby profile image
Simon Herteby • Edited

I searched my js code for .slice, and I think in every single case it could have been replaced by a single one of the take/takeLast/drop/dropLast operations.

Ie. there wasn't even one case where I actually dropped both the beginning and end of a String or Array, the thing that slice is optimized for.

And having to use Array.length is especially ugly indeed.

Btw, if/when you do make this change, it'd be nice to make the APIs of Array, List and String match more (String currently has left/right/dropLeft/dropRight for example.)
They are all lists of stuff after all!