Skip to content

Instantly share code, notes, and snippets.

@dashmug
Created January 23, 2017 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dashmug/98616a2a145be27ef6578feee9575a48 to your computer and use it in GitHub Desktop.
Save dashmug/98616a2a145be27ef6578feee9575a48 to your computer and use it in GitHub Desktop.
Which is better inner or outer functions?
const oneBigFunction = () => {
const add = (x, y) => x + y
const subtract = (x, y) => x - y
const multiply = (x, y) => x * y
const divide = (x, y) => x / y
return divide(add(multiply(8, 1), 2), subtract(3, 1))
}
// or
const add = (x, y) => x + y
const subtract = (x, y) => x - y
const multiply = (x, y) => x * y
const divide = (x, y) => x / y
const smallFunction = () => divide(add(multiply(8, 1), 2), subtract(3, 1))
@dashmug
Copy link
Author

dashmug commented Jan 23, 2017

Obviously, if those inner functions are used somewhere else, I would put them outside the function.

So this question is only about inner functions that are NOT going to be used anywhere else.

Which style is the better one? I'm partial with the small, external functions as I can easily unit-test each function and also easily reuse them. Is there an advantage for the first one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment