17
knerd
6y

When you reduce a function from 16 lines to this, you know ES6 is in good hands now.

Comments
  • 11
    You can do
    const { years, period_types } = this

    Shortening by one more line😃
  • 4
    @leksyib that's cool, i always love to learn such shortcuts
  • 3
    The sick thing about this is, imo it even improves readability.

    In perl for example such one-liners get plain black magic pretty fast but in js, with implicit returns, object deconstruction and stuff you understand it even better.
  • 1
    I would avoid side-effects by making years and period_types and all_periods arguments of this function. Makes unit-testing much easier as you are not dependent on an object state.

    Aim for pure functions.
  • 0
    @k0pernikus probably a class method
  • 1
    And they say they hate js... ^_^
  • 0
    @k0pernikus nice, though it's Vue so it's easier that way
Add Comment