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
| Configuring the setup | |
| 1. Setting up the dependices | |
| yarn init -y (Initalises a packag.json with the default values) | |
| yarn add knex sqlite3 (Add knex sqlite module) | |
| yarn add jest --dev (Add jest to dev dependices) | |
| 2. Adding scripts to the package.json file |
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
| const flatten = (arr) => { | |
| //construct new array so as to not mutate original array | |
| let newArr = [] | |
| //iterate through each item in the array | |
| for(let i = 0; i < arr.length; i++){ | |
| if(arr[i].constructor === Array){ | |
| //if next item in array is an array, recursively call flatten on that array and concat the array returned from that to our new array | |
| newArr = newArr.concat(flatten(arr[i])) | |
| } else { | |
| //if not push value into new array |
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
| The MIT License (MIT) | |
| Copyright (c) 2015 Justin Perry | |
| Permission is hereby granted, free of charge, to any person obtaining a copy of | |
| this software and associated documentation files (the "Software"), to deal in | |
| the Software without restriction, including without limitation the rights to | |
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
| the Software, and to permit persons to whom the Software is furnished to do so, | |
| subject to the following conditions: |
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
| function mapValues(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| result[key] = fn(obj[key], key); | |
| return result; | |
| }, {}); | |
| } | |
| function pick(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| if (fn(obj[key])) { |