One Pager Cheat Sheet
- The code snippet above is a pure function because the output is
solely dependent
on the input variables andnot
on any external environment, as it does not contain any variable declaredoutside of
the function. - The
non-deterministic
nature of the impure function in code snippet 2, due to external variables, makes it inherently unpredictable. - A pure function has a 1-to-1 correspondence between input and output, while an
impure function
has a 1-to-many correspondence due to its dependence on outside variables. - True, a
pure function
can be used to create a 1-to-many relationship between input and output. - Pure functions are
deterministic
and reliable as their output is solely determined by the values of the input parameters and does not depend on global variables. - A
nested function system
is considered pure if it does not trigger anyside effects
such as an HTTP request, mutation of data, printing to a screen, DOM manipulation or Math.random(). - The function
maxplusone
is a pure function with no side effects, as it only callsMath.max()
and adds one to its result.