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 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(""); |
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 initialBodegaState = { | |
insideBodega: false, | |
choppedCheese: 10, | |
catMood: "Neutral", | |
}; | |
const ENTER = { | |
type: 'ENTER_BODEGA', | |
}; |
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
// 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, |
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
// before entering | |
{ | |
insideBodega: false, choppedCheese: 10, catMood: "Neutral", | |
} | |
// after entering | |
{ | |
insideBodega: true, choppedCheese: 10, catMood: "Neutral", | |
} | |
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
// before entering - no actions called | |
{ | |
insideBodega: false, choppedCheese: 10, catMood: "Neutral", | |
} | |
// after entering - ENTER_BODEGA dispatched once | |
{ | |
insideBodega: true, choppedCheese: 10, catMood: "Neutral", | |
} | |
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 initialToDoState = { | |
toDos: [], | |
}; | |
const ADDTODO = { | |
type: 'ADD_TODO', | |
toDo: '' | |
}; | |
const toDoReducer = (state = initialToDoState, action) => { |
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 initialToDoState = { | |
toDos: [], | |
}; | |
const ADDTODO = (toDoValue) => { | |
type: 'ADD_TODO', | |
toDo: toDoValue, | |
}; | |
const toDoReducer = (state = initialToDoState, action) => { |
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 initialToDoState = { | |
toDos: [], | |
}; | |
const ADDTODO = (toDoValue) => { | |
type: 'ADD_TODO', | |
toDo: toDoValue, | |
}; | |
const toDoReducer = (state = initialToDoState, action) => { |
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
// remember that we have a store that we can call on to check the state | |
const store = Redux.createStore(toDoReducer, initialToDoState); | |
// check the state | |
store.getState() | |
// initial state | |
{ toDos: [] } | |
// action ADD_TODO is dispatched with the value 'Buy Food' |
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 characterMatch = (stringA, stringB) => { | |
// basic optimization - store the lengths | |
const aLength = stringA.length; | |
const bLength = stringB.length; | |
// brute force: double for loops | |
// loop over the first argument (stringA) | |
for (let i = 0; i < aLength; i++) { | |
// for every index in stringA, loop over stringB | |
for (let k = 0; k < bLength; k++) { |