Skip to content

Instantly share code, notes, and snippets.

View runandrerun's full-sized avatar
🏠
Working from home

Andre Santiago runandrerun

🏠
Working from home
View GitHub Profile
// before entering - no actions called
{
insideBodega: false, choppedCheese: 10, catMood: "Neutral",
}
// after entering - ENTER_BODEGA dispatched once
{
insideBodega: true, choppedCheese: 10, catMood: "Neutral",
}
// before entering
{
insideBodega: false, choppedCheese: 10, catMood: "Neutral",
}
// after entering
{
insideBodega: true, choppedCheese: 10, catMood: "Neutral",
}
// this reducer takes in the initial state and the action called
bodegaReducer = (state = initialBodegaState, action) => {
// the below switch case decides what to do based on the action
switch(action.type) {
// since 'ENTER_BODEGA' is called
// insideBodega is toggled to be true
case 'ENTER_BODEGA':
return {
...state,
insideBodega: true,
const initialBodegaState = {
insideBodega: false,
choppedCheese: 10,
catMood: "Neutral",
};
const ENTER = {
type: 'ENTER_BODEGA',
};
const closestEnemy = (arr) => {
let player = [];
let enemy = [];
let distance = 0;
let rowLength = arr[0].length;
let board = arr.length;
for (let i = 0; i < board; i++) {
let row = arr[i].split("");
const closestEnemy = (arr) => {
let player = [];
let enemy = [];
let distance = 0;
let rowLength = arr[0].length;
let board = arr.length;
// iterate over the length of the board stored in arrWidth
for (let i = 0; i < board; i++) {
const closestEnemy = (arr) => {
let player = [];
let enemy = [];
let distance = 0;
let rowLength = arr[0].length;
let board = arr.length;
// iterate over the length of the board stored in arrWidth
for (let i = 0; i < board; i++) {
@runandrerun
runandrerun / combinationLock.js
Created November 13, 2018 17:11
Combination Lock Problem Set
combinationLock = (initialState, code) => {
let totalTurns = 0;
initialState.forEach((i, index) => {
let turns = Math.abs(i - code[index]);
if (turns <= 5) {
return (totalTurns += turns);
} else {
const newTurns = 10 - turns;
return (totalTurns += newTurns);
}
combinationLock = (initialState, code) => {
// declare a variable to account for total turns
let totalTurns = 0;
// iterate over the initialState array
// this what the lock looks like when it's first handed to you
initialState.forEach((i, index) => {
// i is the value
Input: Initial State = [2, 3, 4, 5] | Unlock Code = [5, 4, 3, 2]
Output: Rotations required = 8
Explanation : 1st ring is rotated 3 times as 2 => 3 => 4 => 5
2nd ring is rotated 1 time as 3 => 4
3rd ring is rotated 1 time as 4 => 3
4th ring is rotated 3 times as 5 => 4 => 3 =>2
Input: Initial State = [1, 9, 1, 9] | Unlock Code = [0, 0, 0, 0]
Output: Rotations Required = 4
Explanation : 1st ring is rotated 1 time as as 1 => 0