Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
172242f
challenge 1 and 2 completed, forgot to submit yesterday
Aug 9, 2017
9582884
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 10, 2017
1fba9fb
isUnique finished
Aug 10, 2017
4dc5e26
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 11, 2017
0809a69
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 14, 2017
3bec9da
finished callBackPractice
Aug 14, 2017
bdb0e3b
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 15, 2017
0c5d6af
finished waterJugs
Aug 15, 2017
e3cb59d
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 16, 2017
99f7240
finished forLoopTimeout.js
Aug 16, 2017
99c8604
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 17, 2017
3251d64
finished largestPrimePalindrome.js
Aug 17, 2017
f5978d4
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 18, 2017
79ba5fc
finished constructors.js
Aug 18, 2017
bd41f66
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 21, 2017
a1f2fae
finished commonCharacters
Aug 21, 2017
2afb085
removeDuplicates
Aug 21, 2017
296063a
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 22, 2017
75c9600
evenOccurences
Aug 23, 2017
bddb2ba
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 23, 2017
40948c4
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
Aug 24, 2017
46ba47f
finished vowelCount.js
Aug 24, 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
11 changes: 11 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
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 3 quart jug (3:3, 5:0)
transfer water to 5 quart (3:0, 5:3)
fill 3 quart (3:3, 5:3)
transfer 2 quarts from 3 to 5 (3:1, 5:5)
empty 5 quart (3:1, 5:0)
transfer 1 quart to 5 quart (3:0, 5:1)
fill 3 quart and transfer to 5 quart (3:0, 5:4)
the 5 quart jug now has a total of four quarts of water
*/
30 changes: 29 additions & 1 deletion callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,76 @@ firstItem(foods, (firstItem) => {
console.log(`The first item is ${firstItem}.`);
});

const firstItem = () => {
firstItem(foods);
}

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

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

const getLength = () => {
length(foods);
}

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

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

const last = () => {
lastItem(foods);
}

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


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

const sumNums = () => {

}

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

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

const multiplyNums = () => {

}

// 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

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

const contains = () => {

}

// 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.

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

const removeDuplicates = () => {

}

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


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

let newArr = [];
function commonCharacters(str1, str2){
for (var i = 0; i < str1.length; i++) {
for (var j = 0; j < str2.length; j++) {
if (str1[i] === str2[j] && !newArr.includes(str1[i])) {
newArr.push(str1[i]);
}
}
}
return newArr.join('');
}
console.log(commonCharacters('cat', 'cadillac'));
122 changes: 121 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,124 @@
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/
*/

class NPC {
constructor (hp, strength, speed, intelligence, isFriendly, build, attackType, fight) {
this.hp = hp;
this.strength = strength;
this.speed = speed;
this.intelligence = intelligence;
this.isFriendly = isFriendly;
this.build = build;
this.attackType = attackType;
this.fight = fight;
}
attack(enemy) {
enemy.hp -= (Math.floor(Math.random() * 30));
enemy = enemy.toUpperCase();
console.log(`${enemy}'s hp is now at ${enemy.hp}!`);
}
}

class Humanoid extends NPC {
constructor (roboOrBio, speaksEnglish, speaksOther, faveWeapon) {
this.roboOrBio = roboOrBio;
this.speaksEnglish = speaksEnglish;
this.speaksOther = speaksOther;
this.faveWeapon = faveWeapon;
}
}

class Animal extends NPC {
constructor (hasHair, isOmnivore, numLegs, hasTail) {
this.hasHair = hasHair;
this.isOmnivore = isOmnivore;
this.numLegs = numLegs;
this.hasTail = hasTail;
}
}

class Plant extends NPC {
constructor(isPoisonous, isPretty, isTasty, color) {
this.isPoisonous = isPoisonous;
this.isPretty = isPretty;
this.isTasty = isTasty;
this.color = color;
}
}

class Human extends Humanoid {
constructor (isMultilingual, isMarried, birthCity) {
this.isHuman = true;
this.isMultilingual = isMultilingual;
this.isMarried = isMarried;
this.birthCity = birthCity;
}
}

class Elf extends Humanoid {
constructor (earType, height, houseStyle) {
this.earType = earType;
this.height = height;
this.houseStyle = houseStyle;
}
}

class Orc extends Humanoid {
constructor (naughtyOrNice, fightingStyle) {
this.naughtyOrNice = naughtyOrNice;
this.fightingStyle = fightingStyle;
}
}

class Bear extends Animal {
constructor (wildOrTamed, cubOrMama) {
this.wildOrTamed = wildOrTamed;
this.cubOrMama = cubOrMama;
}
}

class Wolf extends Animal {
constructor (howlsAtTheMoon) {
this.hasFangs = true;
this.howlsAtTheMoon = howlsAtTheMoon;
}
}

class FleshEatingDaisy extends Plant {
constructor (name) {
this.isPoisonous = true;
this.isHorrible = true;
this.sucks = true;
this.worstFear = 'Roundup';
this.name = name;
if (this.name !== 'Tulip') {
this.name = 'Tulip';
}
}
}

class Soldier extends Human {
constructor (faveGun, camoColor) {
this.isAwesome = true;
this.faveGun = faveGun;
this.camoColor = camoColor;
}
}

class Peasant extends Soldier {
constructor (isHungry, isLoyal) {
this.isHungry = isHungry;
this.isLoyal = isLoyal;
}
}

class Bandit extends Human {
constructor () {
this.thief = true;
}
steal() {
console.log('The bandit robbed you and got away!');
}
}
17 changes: 17 additions & 0 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,21 @@

const evenOccurence = (arr) => {
// Your code here.
let holder = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i] in holder) {
holder.arr[i]++;
} else {
holder.arr[i] = 1;
}
}
for (var j = 0; j < holder.length; j++) {
if (holder.j % 2 === 0) {
return j;
}
}
return null;
};

const otherArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 6, 2, 8, 3, 6, 4];
console.log(evenOccurence(otherArr));
17 changes: 14 additions & 3 deletions forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
// The output should be 1, 2, 3, .... 10. Right now it just prints 11.
// I've been asked this three times in separate interviews.

//----------------ES5--------------------
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);

console.log(i - 10);
i++;

}, 0);
}

//-----------ES6--------------
for (let i = 1; i <= 10; i++) {
setTimeout(function() {

console.log(i);

}, 0);
}
48 changes: 47 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/

/*
Need to iterate through a string to see if each character is unique
-> create new string variable to hold characters as they are separted from the string argument
if so, return true
otherwise, return false
*/

//If you want to count spaces as characters:

const isUnique = (str) => {
let newStr = '';
for (let i = 0; i < str.length; i++) {
if(newStr.includes(str.charAt(i))) {
return false;
} else {
newStr += str.charAt(i);
}
}
return true;
}
console.log(isUnique('hello'));
console.log(isUnique('hey there'));
console.log(isUnique('name'));
console.log(isUnique('orange'));
console.log(isUnique('Hi man bro'));


//Otherwise:

const isUniqueOther = (str2) => {
let newStr2 = '';
for (let i = 0; i < str2.length; i++) {
if(newStr2.includes(str2.charAt(i))) {
return false;
} else if (str2.charAt(i) !== ' ') {
newStr2 += str2.charAt(i);
}
}
return true;
}
console.log(isUniqueOther('hello'));
console.log(isUniqueOther('hey there'));
console.log(isUniqueOther('name'));
console.log(isUniqueOther('orange'));
console.log(isUniqueOther('Hi man bro'));
31 changes: 30 additions & 1 deletion largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,33 @@
* Hint: it's 929
* You will first want to determine if the number is a palindrome and then determine if it is prime.
* A palindrome is a number that is the same forwards and backwards: 121, 323, 123454321, etc.
*/
*/

function isPalindrome(num) {
if ( num.toString() === num.toString().split( '' ).reverse().join( '' ) ) {
return true;
}
return false;
}

let primesArray = new Array();

function isPrime(num) {
for ( let i = 2; i < num; i++ ) {
if ( num % i === 0 ) {
return false;
}
}
return true;
}

function largestPrimePalindrome() {
for (let i = 2; i < 1000; i++) {
if( isPalindrome(i) && isPrime(i) ) {
primesArray.push(i);
}
}
return primesArray[primesArray.length - 1];
}

console.log(largestPrimePalindrome());
Loading