In this problem set, you'll learn some common coding patterns that you'll use for the rest of your programming career!
Test files are already written for you in the __tests__
folder. Complete the functions in the patterns
folder according to each section below. The first problem of each section comes with a sample solution that you can use as reference.
A guard is a conditional usually placed at the beginning of a function that prevents the rest of the function from being run if certain conditions are not met. A function can have more than one guard.
Complete the functions in guard.js
to pass the tests in guard.test.js
.
An accumulator variable is used to keep track of information as a program executes, usually alongside a loop. Sometimes, the accumulator variable might update depending on a condition.
Complete the functions in accumulator.js
to pass the tests in accumulator.test.js
.
Almost all of the functions we've seen so far return something at the very end. If we already have an answer, we don't always need to iterate through the entire array. For these problems, think about what to return and when to return!
Complete the functions in timing.js
to pass the tests in timing.test.js
.
You can loop inside a loop, and you can have arrays of arrays!
Complete the functions in nested.js
to pass the tests in nested.test.js
.
Please submit the link to your public GitHub repository.