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
@runandrerun
runandrerun / spotUniqueCharSet.js
Created February 6, 2020 00:50
spotUniqueCharSet
const paragraph = "If you want to jumpstart the process of talking to us about this role, here’s a little challenge: write a program that outputs the largest unique set of characters that can be removed from this paragraph without letting its length drop below 50.";
const spotUniqueCharSet = (paragraph) => {
const dictionary = {};
const sortedDictionary = {};
let characterSet = [];
let sortable = [];
let paragraphLength = paragraph.length;
// map over paragraph to find unique appearance counts in the paragraph provided
// 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,
function fibonacci(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
const dictionaryMatch = (stringA, stringB) => {
// create an empty dictionary to store your string
const dictionary = {};
// split stringA by character and iterate over it
// create a new key value pair in the dictionary
// for each unique character within the array
stringA.split('').forEach(character => {
dictionary[character] = character;
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++) {
// 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'
const initialToDoState = {
toDos: [],
};
const ADDTODO = (toDoValue) => {
type: 'ADD_TODO',
toDo: toDoValue,
};
const toDoReducer = (state = initialToDoState, action) => {
const initialToDoState = {
toDos: [],
};
const ADDTODO = (toDoValue) => {
type: 'ADD_TODO',
toDo: toDoValue,
};
const toDoReducer = (state = initialToDoState, action) => {
const initialToDoState = {
toDos: [],
};
const ADDTODO = {
type: 'ADD_TODO',
toDo: ''
};
const toDoReducer = (state = initialToDoState, action) => {
// before entering - no actions called
{
insideBodega: false, choppedCheese: 10, catMood: "Neutral",
}
// after entering - ENTER_BODEGA dispatched once
{
insideBodega: true, choppedCheese: 10, catMood: "Neutral",
}