Challenges from Doug Crockford's JavaScript Good Parts course on Front-end Masters which can be found at https://frontendmasters.com/courses/javascript-the-good-parts/
My answers are written in both ES3/5 and ES6 (ES-2015)
- Write a function that takes an argument and returns that argument.
- Write two binary functions,
add
andmul
, that take two numbers and return their sum and product. - Write a function that takes an argument and returns a function that returns that argument.
- Write a function that adds from two invocations.
- Write a function that takes a binary function, and makes it callable with two invocations.
- Write a function that takes a function and an argument, and returns a function that can supply a second argument.
- Without writing any new functions, show three ways to create the
inc
function. Using functions from the previous six problems. - Write
methodize
, a function that converts a binary function to a method. - Write
demethodize
, a function that converts a method into a binary function. - Write a function
twice
that takes a binary function and returns a unary function, that passes it's argument to the binary function twice. - Write a function
composeu
that takes two unary functions and returns a unary function that calls them both. - Write a function
composeb
thst takes two binary functions and returns a function that calls them both. - Write a function that allows another function to be only called once.
- Write a factory function that returns two functions that implement an up/down counter.
- Make a revocable function that takes a nice function and returns a
revoke
function that denies access to the nice function, and aninvoke
function that can invoke the nice function until it is revoked.