Nope, the function will remain pure because primitive types in JavaScript are passed by value. This means when i is passed in as an argument, pureInsert creates a brand new functional context that contains its own copy of i as opposed to referencing the original variable that was passed in. Since the function cannot mutate the original variable, purity is maintained.
Nope, the function will remain pure because primitive types in JavaScript are passed by value. This means when
i
is passed in as an argument,pureInsert
creates a brand new functional context that contains its own copy ofi
as opposed to referencing the original variable that was passed in. Since the function cannot mutate the original variable, purity is maintained.If you really wanted to make the
++
operator "impure", you could use a higher-order function.I didn't know that. Thanks for the clarification.
Sure thing! :)