This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create react app | |
- `npx create-react-app <app-location>` | |
- cd to new react app directory | |
# Add eslint (StandardJS) | |
- `npm install standard --save-dev` | |
- `touch eslintrc.yml && echo "extends: standard" >> eslintrc.yml` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted from https://gist.github.com/aherve/741753e1f25e4c87450e6aebe590134b | |
// more info on Set: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set | |
// Get a unique array of numbers | |
const numbersArr = [4, 1, 2, 1, 1, 2, 1, 3, 4, 1 ] | |
const uniqNumArr = [...new Set(numbersArr)] // => [ 4, 1, 2, 3 ] | |
const uniqNumArrSorted = [...new Set(numbersArr)].sort(); // => [ 1, 2, 3, 4 ] | |
// Get a unique array of strings (unsorted) | |
const strArr = ['c', 'a', 'b', 'c', 'c', 'c', 'd', 'a']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fibonacci sequence for increased delay algorithm | |
// return number in sequence at given index | |
const fib = (a) => { | |
const arr = [0, 1]; | |
let i = a; | |
if (i > 30) { i = 30; } // safeguard against recursion | |
for (let n = 0; n < i; n++) { | |
const last = arr[arr.length - 1]; | |
const nextToLast = arr[arr.length - 2]; | |
const sum = nextToLast + last; |