Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a762ea3
longestString challenge complete
phytertek Aug 8, 2017
fca37ca
updated for null edge case
phytertek Aug 8, 2017
39bfe2c
Day 3 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 9, 2017
d86f3a7
Reverse Case Complete
phytertek Aug 9, 2017
0057614
fixed accidental change to longestString
phytertek Aug 9, 2017
38bbef1
Reverse String refactor if/else to ternary
phytertek Aug 9, 2017
d51b576
Day 4 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 10, 2017
664d957
isUnique challenge complete
phytertek Aug 10, 2017
c1cdfe7
refactor to use Set
phytertek Aug 10, 2017
8a7f671
Day 5 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 11, 2017
09e7e2f
callBackPractice complete
phytertek Aug 11, 2017
5ea9d06
fix ordering of functions in callBackPractice
phytertek Aug 11, 2017
1ad6682
fix typo in contains function on callBackPractice
phytertek Aug 11, 2017
aef4b5b
fix
phytertek Aug 11, 2017
2509b4d
Day 6 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 14, 2017
d41ec73
removeDuplicates complete
phytertek Aug 14, 2017
260a60a
Day 7 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 15, 2017
0804634
Water Jugs challenge complete
phytertek Aug 15, 2017
5805607
Day 8 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 16, 2017
7a0ff02
forLoopTimeout challenge complete
phytertek Aug 16, 2017
72c0471
typo
phytertek Aug 16, 2017
ce0aa7b
Day 8 Merge branch 'master' of https://github.com/LambdaSchool/CS2-Co…
phytertek Aug 17, 2017
757ee91
largestPrimePalindrome challenge complete
phytertek Aug 17, 2017
2ae39a4
optimization1 of largestPrimePalindrome
phytertek Aug 17, 2017
aecf2de
fix tabs
phytertek Aug 17, 2017
1e8a8a7
var to let
phytertek Aug 17, 2017
86e0c76
Just Checking... Merge branch 'master' of https://github.com/LambdaSc…
phytertek Aug 18, 2017
624bdb6
Day 10 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 18, 2017
e7665f5
Constructors challenge complete
phytertek Aug 18, 2017
bdfc748
Added Frank's soulution... damn its fast!
phytertek Aug 18, 2017
ff35b79
change
phytertek Aug 20, 2017
914a32b
a change
phytertek Aug 20, 2017
45003f1
Day 11 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 21, 2017
3526b5b
commonCharacters solution complete
phytertek Aug 22, 2017
b38cbb5
fix typo in commonCharacters
phytertek Aug 22, 2017
cf85543
Day 12 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 22, 2017
46bcb54
evenOccurances challenge complete
phytertek Aug 22, 2017
2d41d04
changed
phytertek Aug 22, 2017
290f402
changed again
phytertek Aug 22, 2017
9adabc7
Day 12 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 23, 2017
54b539c
stringCompression complete
phytertek Aug 23, 2017
a786784
Day 13 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 24, 2017
3aa2f84
fix evenOccurance to account for ES6 Object traversal of integer keys
phytertek Aug 24, 2017
c9be8b8
vowelCount challenge complete
phytertek Aug 24, 2017
d6f1032
fix vowelCount to ignore case in regex
phytertek Aug 24, 2017
dd3e22d
Remove uneccessary if from stringCompression function
phytertek Aug 24, 2017
b7e38c9
Day 15 Merge branch 'master' of https://github.com/LambdaSchool/CS2-C…
phytertek Aug 25, 2017
624e0b0
meanMedianMode challeng complete
phytertek Aug 25, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.

# fill the 3 quart jug

# pour the 3 quarts into the 5 quart jug

# flll the 3 quart jug

# fill the remainder of the 5 quart jug, leaving 1 quart in the 3 quart jug

# empty the 5 quart jug

# pour the remaining 1 quart from the 3 quart jug into the 5 quart jug

# fill the 3 quart jug

# pour the 3 quarts into the 5 quart jug

# the 5 quart jug now contains 4 quarts
14 changes: 14 additions & 0 deletions callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,65 @@

const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango'];

const firstItem = (arr, cb) => cb(arr[0]);

firstItem(foods, (firstItem) => {
console.log(`The first item is ${firstItem}.`);
});

// Write a function called getLength that passes the length of the array into the callback

const getLength = (arr, cb) => cb(arr.length);

getLength(foods, (length) => {
console.log(`The length of the array is ${length}.`);
});

// Write a function called last which passes the last item of the array into the callback

const last = (arr, cb) => cb(arr[arr.length - 1]);

last(foods, (lastItem) => {
console.log(`The last item in the array is ${lastItem}.`);
});

// Write a function called sumNums that adds two numbers and passes the result to the callback

const sumNums = (a, b, cb) => cb(a + b);

sumNums(5, 10, (sum) => {
console.log(`The sum is ${sum}.`);
});

// Write a function called multiplyNums that adds two numbers and passes the result to the callback

const multiplyNums = (a, b, cb) => cb(a * b);

multiplyNums(5, 10, (product) => {
console.log(`The product is ${product}.`);
});

// Write a function called contains that checks if an item is present inside of the given array.
// Pass true to the callback if it is, otherwise pass false

const contains = (arr, item, cb) => cb(arr.indexOf(item) !== -1)

contains(foods, 'ribeye', (result) => {
console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array');
});

// Write a function called removeDuplicates that removes all duplicate values from the given array.
// Pass the array to the callback function. Do not mutate the original array.

const removeDuplicates = (arr, cb) => cb(Array.from(new Set(arr)))

removeDuplicates(foods, (uniqueFoods) => {
console.log(`foods with duplicates removed: ${uniqueFoods}`);
});

// Write a function called forEach that iterates over the provided array and passes the value and index into the callback.

const forEach = (arr, cb) => arr.forEach((v, i) => cb(v, i)); // <- Instructions never said not to use array builtin methods ;)

forEach(foods, (value, index) => {
console.log(`${value} is at index ${index}.`);
Expand Down
17 changes: 17 additions & 0 deletions commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@
* Example: commonCharacters('acexivou', 'aegihobu') *
* Returns: 'aeiou'
*/
const test1 = 'acexivj oujdf';
const test2 = 'aeg ihobujj';

const commonCharacters = (str1, str2) => {
const seen = {};
let common = '';
const matches = str1.match(new RegExp('(['+str2+'])', 'g'))
for (let i = 0; i < matches.length; i++){
if (matches[i] !== ' ' && !seen[matches[i]]) {
common += matches[i];
seen[matches[i]] = true;
}
}
return common
}

console.log(commonCharacters(test1, test2))
148 changes: 125 additions & 23 deletions constructors/constructors.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,125 @@
/* Design several classes and their relationships for an RPG videogame.
* Classes:
* NPC -> Humanoid, Animal, Plant
* Humanoid -> Human, Elf, Orc
* Animal -> Bear, Wolf
* Plant -> FleshEatingDaisy
*
* Human -> Soldier, Peasant, Bandit
*
* NPC should be a general class for a non-player character in the game.
* This class will probably include general attributes like hp, strength, speed, etc.
*
* Humanoid, Animal, and Plant should all inherit from NPC. The classes
* shown to the right of the arrow are classes that will inherit
* from those classes.
*
* Soldier, Peasant, and Bandit should all inherit from Human.
*
* Create properties for these different classes that fit with the character.
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/


/*
* Design several classes and their relationships for an RPG videogame.
* Classes:
* NPC -> Humanoid, Animal, Plant
* Humanoid -> Human, Elf, Orc
* Animal -> Bear, Wolf
* Plant -> FleshEatingDaisy
*
* Human -> Soldier, Peasant, Bandit
*
* NPC should be a general class for a non-player character in the game.
* This class will probably include general attributes like hp, strength, speed, etc.
*
* Humanoid, Animal, and Plant should all inherit from NPC. The classes
* shown to the right of the arrow are classes that will inherit
* from those classes.
*
* Soldier, Peasant, and Bandit should all inherit from Human.
*
* Create properties for these different classes that fit with the character.
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/

class NPC {
constructor(attr) {
this.hp = attr.hp;
this.strength = attr.strength;
this.speed= attr.speed;
this.attack = attr.attack;
this.defend = attr.defend;
}
}

class Humanoid extends NPC {
constructor(attr) {
super(attr)
// Humanoid Attributes
this.weapon = attr.weapon;
}
}

class Animal extends NPC {
constructor(attr) {
super(attr)
// Animal Attributes
}
}

class Plant extends NPC {
constructor(attr) {
super(attr)
// Plant Attributes
}
}

class Human extends Humanoid {
constructor(attr) {
super(attr)
// Human Attributes
}
}

class Elf extends Humanoid {
constructor(attr) {
super(attr)
// Elf Attributes
}
}

class Orc extends Humanoid {
constructor(attr) {
super(attr)
// Orc Attributes
}
}

class Bear extends Animal {
constructor(attr) {
super(attr)
// Bear Attributes
}
}

class Wolf extends Animal {
constructor(attr) {
super(attr)
// Wolf Attributes
}
}

class FleshEatingDaisy extends Plant {
constructor(attr) {
super(attr)
// FleshEatingDaisy Attributes
}
}

class Soldier extends Humanoid {
constructor(attr) {
super(attr)
// Soldier Attributes
}
}

class Peasant extends Humanoid {
constructor(attr) {
super(attr)
// Peasant Attributes
}
}

class Bandit extends Humanoid {
constructor(attr) {
super(attr)
// Bandit Attributes
}
}

const sl = new Soldier({hp: 100})

console.log(sl)
20 changes: 20 additions & 0 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,24 @@

const evenOccurence = (arr) => {
// Your code here.
const occurances = {}
let returnVal = null
for (let i = 0; i < arr.length; i++) {
if (occurances['0'+arr[i]]) occurances['0'+arr[i]]++;
else occurances['0'+arr[i]] = 1;
}
const occuranceKeys = Object.keys(occurances);
for (let j = 0; j < occuranceKeys.length; j++) {
if(occurances[occuranceKeys[j]] % 2 === 0) {
returnVal = occuranceKeys[j].splice(0,1);
break;
}
}
Reflect
return returnVal;
};

const onlyEven = evenOccurence([1, 7, 4, 2, 5, 1, 6, 8, 9, 6, 4, 3, 2, 1]);
console.log(onlyEven); // 4

console.log(evenOccurence([1,2,3,4,5]))
22 changes: 16 additions & 6 deletions forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
// I've been asked this three times in separate interviews.

for (var i = 1; i <= 10; i++) {
setTimeout(function() {
// From looking at the code you would assume it would print 1 - 10
// It doesn't. Why? How can you make it print 1 - 10.
console.log(i);
}, 0);
}
doSetTimeout(i)
}

function doSetTimeout(i) {
setTimeout(function() {
console.log(i)
}, 0);
}

// If you don't do something like this (and there are other variations on
// this same idea), then each of the timer handler functions will share the
// same variable "i". When the loop is finished, what's the value of "i"?
// It's 11!
// By using an intermediating function, a copy of the value of the
// variable is made. Since the timeout handler is created in the context of
// that copy, it has its own private "i" to use.
33 changes: 32 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/

// Test Cases
/**
* 'AAABBBCCC' => false
* 'ABCDEFGHI' => true
* 'AaBbCcDdEe' => true
* 'ABCabcABCabc' => false
* '' => true
*/

// Psuedo Code
/**
* create a new Set with the string char values (which automatically dedupes string chars)
* return set size compared to string length
*/

//Solution
const isUnique = (string) => new Set(string).size === string.length

//Tests
const test1 = 'AAABBBCCC' // => false
const test2 = 'ABCDEFGHI' // => true
const test3 = 'AaBbCcDdEe' // => true
const test4 = 'ABCabcABCabc' // => false
const test5 = '' // => true

console.log(isUnique(test1))
console.log(isUnique(test2))
console.log(isUnique(test3))
console.log(isUnique(test4))
console.log(isUnique(test5))
Loading