Adding 0 to a balance on an object How can I refactor this into one line? Is that possible, even with ES6 syntax?

export const zeroBalance = (coin) =&gt; {
    coin.balance = 0;
    return coin;
};
How can I refactor this into one line? Is that possible, even with ES6 syntax?

export const zeroBalance = (coin) =&gt; {
  coin.balance = 0;
  return coin;
};



Yes, that's easily possible. Newlines aren't required in ECMAScript:

export const zeroBalance = coin =&gt; { coin.balance = 0; return coin; };


Ruby has an implementation of the K Combinator as Object#tap for exactly that use case. ECMAScript doesn't, but it's easy to implement:

 function k(obj, f) { f(obj); return obj };


This would allow you to rewrite your code like this:

export const zeroBalance = coin =&gt; k(coin, c =&gt; c.balance = 0);