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 isSubset = (arr1, arr2) => { | |
for (let i = 0; i < arr2.length; i++) { | |
if (!arr1.find(ele => ele === arr2[i])) { | |
// console.log(item); | |
return false; | |
} | |
} | |
return true; | |
}; |
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
.site{ | |
display:grid; | |
grid-template-columns:2fr 1fr; | |
grid-template-areas:"header header" | |
"title sidebar" | |
"main sidebar" | |
"footer footer"; | |
} | |
.site > *{padding:30px; color:#fff; font-size:20px;} | |
.mastheader{ grid-area:header; } |
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
// Error Object | |
const Error = new Error(‘please improve your code’) | |
Error.message //please improve your code | |
Error.stack | |
//Error: please improve your code | |
// at Object.<anonymous> (/Users/gisderdube/Documents/_projects/hacking.nosync/error-handling/src/general.js:1:79) | |
// at Module._compile (internal/modules/cjs/loader.js:689:30) | |
// at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) | |
// at Module.load (internal/modules/cjs/loader.js:599:32) |
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
# require express | |
# optional mongoDB and body-parser | |
const express = require('express'); | |
const mongoose = require("mongoose"); | |
const bodyParesr = require("body-parser"); | |
require("") //schema for mongodb | |
const app = express(); |
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
inner border radius = border radius - border width (border radius > border width) | |
.app{ | |
border-radius: 10px; | |
border-width: 8px | |
} |
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
// can make a parameter optional | |
// make the return value much richer | |
const human = ({name, contact, age}={}) => { | |
return {name, contact, age} | |
} | |
const Paul = human({name="Paul", age="32"}) |
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
// how to do inheritance | |
// passing in the prototype function | |
// Object.freeze make only shallow copies | |
function makeProductList({ productDb }) { | |
return Object.freeze({ | |
addProduct, | |
empty, | |
getProducts, | |
removeProduct, |
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 dog = () => { | |
const sound = "woof!" | |
return { | |
bark: ()=>{console.log(sound)} | |
} | |
} | |
const sniffles = dog(); | |
sniffles.talk() //output: "woof!" |
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
import fs from 'fs'; | |
// read file | |
function jsonReader(filePath, cb) { | |
fs.readFile(filePath, (err, fileData) => { | |
if (err) { | |
return cb && cb(err) | |
} | |
try { | |
const object = JSON.parse(fileData) |
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
// setState within syntheitc event | |
// setState is async, by the time the action finished, | |
// event.target.value is no longer the same | |
// so need event.persist() to maintain the value | |
// if you want to access currentTarget in async way, you need to cache it in a variable as you did in your answer. | |
const Searchbar = ({getNutrition}) => { | |
const [searchState, setSearchState] = useState("ingredient") | |
const selValue = (ev) => { |
NewerOlder