This file contains 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
/* eslint-disable */ | |
router.use((err, req, res, next) => { | |
res.status(err.status || 500).json({ | |
fromTheDev: 'mistakes were made', | |
message: err.message, | |
stack: err.stack, | |
}) | |
}) | |
/* eslint-enable */ |
This file contains 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 sharedConfig = { | |
client: 'sqlite3', | |
useNullAsDefault: true, | |
migrations: { | |
directory: './data/migrations', | |
}, | |
seeds: { | |
directory: './data/seeds', | |
}, | |
pool: { |
This file contains 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 knex = require('knex') | |
const configs = require('../knexfile.js') | |
const environment = process.env.NODE_ENV || 'development' | |
module.exports = knex(configs[environment]) |
This file contains 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
// always use as first seed file to clean db | |
const cleaner = require('knex-cleaner') | |
exports.seed = function (knex) { | |
return cleaner.clean(knex, { | |
mode: 'truncate', // resets ids | |
ignoreTables: [ | |
'knex_migrations', | |
'knex_migrations_lock' | |
], |
This file contains 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
"scripts": { | |
"start": "node index.js", | |
"server": "nodemon index.js", | |
"migrate": "knex migrate:latest", | |
"rollback": "knex migrate:rollback", | |
"seed": "knex seed:run", | |
"test": "cross-env NODE_ENV=test jest --runInBand --verbose --watch --setTimeout=500" | |
}, |
This file contains 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
knex | |
.select([ | |
'users.*', | |
knex.raw('json_agg("posts") as posts') | |
]) | |
.from('users') | |
.leftJoin(function () { | |
this.select(['posts.*', knex.raw('json_agg("comments") as comments')]) | |
.from('posts') | |
.leftJoin('comments', { 'posts.id': 'comments.post' }) |
This file contains 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
/* | |
This challenge is slightly misleading, as it says to reverse a string but inputs an array and expects an | |
array as output. If you need to return this as a string, use the String.join() method | |
*/ | |
const reverseString = s => { | |
const reverseArray = s.reverse() | |
return reverseArray | |
}; |
This file contains 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 numIslands = grid => { | |
// need variable to count islands | |
let islands = 0 | |
// create a function to search for 1 and use recursion to search surrounding cells | |
const findIslands = (row, col, grid) => { | |
// first check if row and col exist on grid and if grid[row][col] 0 | |
if ( | |
row < 0 || | |
col < 0 || |
This file contains 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 twoSum = (nums, target) => { | |
// given an array, return pair of indices corresponding to numbers in array that equal target | |
// there is exactly 1 solution per array of nums | |
// need variable to store indices of solution | |
const solution = [] | |
// need variable to store count to leverage while loop | |
let count = 0 | |
This file contains 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 isAnagram = (s, t) => { | |
if (s.split('').sort().join('') == t.split('').sort().join('')) { | |
return true | |
} | |
return false | |
}; |
OlderNewer