Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.