r/reactjs • • Dec 02 '21

Meta Coding Interview with Dan Abramov

https://www.youtube.com/watch?v=XEt09iK8IXs
618 Upvotes

140 comments sorted by

View all comments

Show parent comments

1

u/franciscopresencia Dec 03 '21

Nice! Editing it a bit, I like this slightly more:

const invertTree = (node) => node && {
  left: invertTree(node.right),
  right: invertTree(node.left),
  value: node.value,
};

0

u/[deleted] Dec 05 '21

This one doesn't modify it in place, but looks nice as an immutable alternative.