- Install dependencies with
yarn - Run
yarn testto check that jest runs the tests but they fail for sensible reasons - Consult the tests and edit myFunctions.js
- implement the functions in myFunctions.js until all tests pass.
- Follow the setup steps as per task 1 if you have not already done so
- run
yarn test mapPracticeto only run the tests for this task - Consult the tests in mapPractice.test.js
- and edit the functions in mapPractice.js
- implement the functions until all tests pass.
You should use the array.map function in your solution for each of these functions.
Run tests on every change
By adding --watch to an instruction to jest, you can cause tests to be re-run every time a relevant file is changed. E.g.
yarn test mapPractice --watchRun only one test
Note that you can amend a test to be the only one to run, when you want to focus on it, as follows:
test.only("square all numbers"instead of
test("square all numbers"Weirdly, your code should not contain any loop structures (no for or while loops).
Unlike in some earlier katas, for this set of exercises you should try to make use of some of the built-in js array methods instead.
Specifically, you should research the following, to see which ones can help you. (You won't need them all.)
- array.find
- array.findLast
- array.findIndex
- array.filter
- array.some
- array.includes
- array.indexOf
- array.every
- array.map
- It's fine to make little helper functions to get the work done
- It's fine to use arrow functions or normal function declaration syntax wherever you like, except...
- Don't change the signature (first line) of the given functions, nor their jsdoc, only their bodies.
- (so, also don't change the form of the existing functions to be arrow functions.)
- It should not be necessary to edit the test file. (though you are welcome to add MORE tests to give further clarity or visibility into any problem)