For this practice WOD, solve the following variation of the first of the five problems that Santiago Valdarrama thinks should take less than an hour.
Ready? Let’s begin:
-
Start your timer.
-
Create an empty GitHub repo called “sumofnumbers” and clone it to your local computer. Don’t forget to check the box so that a README file is created.
-
Open the local repo in VSCode.
-
Set up your project to use our Typescript coding standards. Download five files into your project directory:
sample.eslintrc.js
, rename it to.eslintrc.js
.sample.eslintignore
, rename it to.eslintignore
.sample.gitignore
, rename it to.gitignore
.sample.package.json
, rename it topackage.json
.sample.tsconfig.json
, rename it totsconfig.json
.
-
Invoke
npm install
to install ESLint. -
Create two files:
index.html
andsumofnumbers.ts
. Theindex.html
should load thesumofnumbers.js
file. Remember to compile your Typescript file to Javascript. Usenpx tsc
to compile your Typescript file. -
Write four functions that return the sum of the numbers in a given list using:
- a for-loop,
- a while-loop,
- recursion, and
- Array functional programming.
Call them
sumFor
,sumWhile
,sumRecursion
, andsumTheFunctionalWay
. Addconsole.log
statements to each function to show the result. For example,console.log(sumFor([1, 2, 3, 4]));
should output10
. Check the output in the browser console. -
Make sure ESLint is running. For example, add newlines to the end of a file to see that an ESLint error is triggered.
-
Make sure that there are no red ESLint errors indicating ESLint does not detect any problems with your code.
-
Commit your finished program to GitHub.
-
Check that your code is on GitHub.
-
Stop your timer and record your time. Be sure to record it, because you will need your WOD time data when you write your technical essay.