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
/** | |
@function generateRawDataFromSettings | |
receives differently shaped input data from various settings components, | |
containing users choices. | |
@param {FSA} settingsData | |
@return {object} | |
*/ | |
/** |
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
import { v4 as generateId } from 'immutable'; | |
//------------- CUSTOM HOOK ------------- | |
export function useSetState(initialState) { | |
const [state, setState] = useReducer((prevState, action) => { | |
// HERE we can have normal reducer logic to handle the action and create a "newState" | |
if (someAction === someValue) { | |
if (!state.reqids.includes(action.meta.reqId)) return state; | |
// do something with the action.payload | |
} | |
// finally, return the new state |
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
import { v4 as generateId } from 'uuid'; | |
function SomeModule() { | |
const [reqIds, setReqIds] = useState([]); | |
const [state, localDispatch] = useReducer(createReducer(reqIds), initialState); | |
function getSomeData(reqId) { | |
const newReqId = generateId(); | |
setReqIds(newReqId) |
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 */ | |
let result = ''; | |
let test = "tobiah is happy eandhelovestocode fordaysanddaysanddays"; | |
[ | |
'tobiah', | |
'is', | |
'happy', | |
'eandhelovestocode', | |
'fordaysanddaysanddays' | |
] |
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
/* | |
REMEMBER: | |
1. Restart server when you write new Logic changes. | |
2. Run server with "node <name of file>.js" | |
3. Add npm packages with "yarn add <package name>" (Make sure Yarn is globally installed) | |
*/ | |
const express = require('express'); | |
const fs = require('fs'); | |
const morgan = require('morgan'); |
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 gcd = (n1, n2) => { | |
if (n2 === 0) return n1; | |
return gcd(n2, n1 % n2); | |
} | |
const main = (input) => { | |
if (gcd(input[0], input[1]) == gcd(input[2], input[3])) { | |
return 'YES'; | |
} else return 'NO'; | |
} |
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
/* | |
String Rotation: Assume you have a method isSubstring which | |
checks if one word is a substring of another. | |
Given two strings, sl and s2, | |
write code to check if s2 is a rotation of sl | |
using only one call to isSubstring | |
(e.g., "waterbottle" is a rotation of"erbottlewat"). | |
*/ |
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
var express = require('express') | |
var app = express() | |
var http = require('http').Server(app) | |
app.use(express.static(__dirname)) | |
app.get('/', function(req,res){ | |
res.sendFile(__dirname + '/index.html') | |
}) | |
const WebSocket = require('ws'); |
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
/* | |
HackerRank standardizes its input stream for many of its challenges. | |
This function can be optimized to account for different input types. | |
Simply change variable names etc. | |
*/ | |
function parseInputs(input) { | |
const inputs = input.split('\n'); | |
const testCases = Number(inputs[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 problem = { | |
start: {A: 5, B: 2}, | |
A: {C: 4, D: 2}, | |
B: {A: 8, D: 7}, | |
C: {D: 6, finish: 3}, | |
D: {finish: 1}, | |
finish: {} | |
}; | |
const lowestCostNode = (costs, processed) => { |