Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
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.

//5 Quart //3 Quart

need: 4 quarts.

**///////////////\\\\\\\\\\\\\\**

I would fill up the 5 quart jug fully. Pour our 3 quarts into the 3 quart jug- take the remaining 2 quarts and put into the 4 quart jug.

I would then rinse and repeat. I would fully empty the 3 quart jug.

Fill the 5 quart jug again- pour 3 quarts into 3qt jug and fill the rest of the four quart jug with the remaining two quarts.

***/////////////////\\\\\\\\\\\\\\\\\\\***
Step 1:
Fill 5 to top,

Step 2:
Empty 5quart to 3quart,
there will be 2quart remaining,

Step 3:
take remaining 2quart to fill 4quart halfway.

Step 4:
Repeat steps 1 - 3 to completion of task.
45 changes: 44 additions & 1 deletion callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,93 @@

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

const firstItem = (foods, cb) => {
cb(foods[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 = (foods, cb) => {
cb(foods.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 = (foods, cb) => {
cb(foods[foods.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 = (num1, num2, cb) => {
cb(num1 + num2);
};
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 =(num1, num2, cb) => {
cb(num1 * num2);
};


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 = (foods, item, cb) => {
for(let i = 0; i < foods.length; i++){
if(foods[i] === item){
cb(true);
}
}
return false;
}

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 = (foods, cb) => {
for (let i = 0; i < foods.length; i++){
if(foods[i]===foods[i])

}
}


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 = (foods, cb) => {
for (let i = 0; i < foods.length; i++){
cb(foods[i], i);
}
}




forEach(foods, (value, index) => {
Expand Down
16 changes: 16 additions & 0 deletions commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
* Example: commonCharacters('acexivou', 'aegihobu') *
* Returns: 'aeiou'
*/
<<<<<<< HEAD
const commonChars = (string1, string2) => {
let combinedStr = '';
for(let i = 0; i < string1.length; i++){
for(let j = 0; j < string2.length; j++){
if(string1[i] === string2[j]){
combinedStr += string1[i];
}
}
}
return combinedStr;
}

console.log(commonChars('acexivou', 'aegihobu'));``
=======
>>>>>>> e4337df47805c308e007181cf6cdc974564b766c
112 changes: 111 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,114 @@
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/
*/

class NPC {
constructor(options) {
this.hp = options.hp;
this.strength = options.strength;
this.agility = options.agility;
this.intellect = options.intellect;
}
}
class Humanoid extends NPC {
constructor(options) {
super(options);

}
}
class Animal extends NPC {
constructor(options) {
super(options);
}
}
class Plant extends NPC {
constructor(options) {
super(options);
}
}
class Human extends Humanoid {
constructor(options) {
super(options);
this.name = options.name;
this.hairColor = options.hairColor;
this.skinColor = options.skinColor;
this.facialHair = options.facialHair;
this.height = options.height;
}
}
class Elf extends Humanoid {
constructor(options) {
super(options);
this.name = options.name;
this.hairColor = options.hairColor;
this.skinColor = options.skinColor;
this.height = options.height;
}
}
class Orc extends Humanoid {
constructor(options) {
super(options);
this.name = options.name;
this.hairColor = options.hairColor;
this.skinColor = options.skinColor;
this.scars = options.scars;
this.facialHair = options.facialHair;
this.height = options.height;
}
}
class Bear extends Animal {
constructor(options) {
super(options);
this.typeOfBear = options.typeOfBear;
this.size = options.size;
this.ferocity = options.ferocity;
}

}
class Wolf extends Animal {
constructor(options) {
super(options);
this.typeOfWolf = options.typeOfWolf;
this.size = options.size;
this.ferocity = options.ferocity;

}
}
class FleshEatingdaisy extends Plant {
constructor(options) {
super(options);
this.size = options.size;
this.color = options.color;
}
}
class Solider extends Human {
constructor(options) {
super(options);
this.tacticalMind = options.tacticalMind;
this.weaponMastery = options.weaponMastery;
this.willToLive = options.willToLive;
}
}
class Peasant extends Human {
constructor(options) {
super(options);
this.workEthic = options.workEthic;
this.barteringSkill = options.barteringSkill;
this.woodWorking = options.woodWorking;
this.fishing = options.fishing;
this.hunting = options.hunting;
this.blacksmithing = options.blacksmithing;
}
}
class Bandit extends Human {
constructor(options) {
super(options);
this.guile = options.guile;
this.archery = options.archery;
this.speed = options.speed;
this.pickPocket = options.pickPocket;
this.traps = options.traps;
this.morality = options.morality;
}
}
17 changes: 16 additions & 1 deletion evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@
* */

const evenOccurence = (arr) => {
// Your code here.
let count = 0;
let element = 0;
for(let i = 0; i < arr.length; i++){
let tempInt = arr[i];
let tempCount = 0;
for(let j = 0; j < arr.length; j++){
if(arr[j] === tempInt){
tempCount++;
}
}
if(tempCount % 2 === 0 && tempCount > count){
count = tempCount;
element = tempInt;
}
}
return element;
};
31 changes: 30 additions & 1 deletion forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,33 @@ for (var i = 1; i <= 10; i++) {
// It doesn't. Why? How can you make it print 1 - 10.
console.log(i);
}, 0);
}
}

////////////////////\\\\\\\\\\\\\\\\\\
for (var i = 1; i <= 10; i++) {
setDelay(i);
}

function setDelay(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. // **Written answer below***
console.log(i);
},0);
}

//The code fix was the result of some googling.
// Looking this over again and again didn't make much sense as to why this was not working as intended
//After reading the explanation- it all became apparent.
//The explanation is as follows:
/* We have to arrange a distinct copy of 'i' to be present for each of the timeout functions.
If we don't do something like this, then each of the timer handler functions will share the same variable i.
*/

/* My take away from the above is this: We need to make a call back function in order to separate the 'i' values
so the 'i' values don't overwrite each other and make a grand sum to print 10 times. When making a call back function,
we allow the 'i' value to be separated by the loop which in turn allows the loop to properly iterate through the numbers. */

//To be completely honest alot of this stuff is really foggy at the moment and I have a fingertip grasp on much of these concepts
//so my explanation can be completely off- trying my hardest, feel like a dumby, but pushing through in the hopes that this all makes
//sense soon.
24 changes: 23 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/


const isUnique = (string) => {
let uniqueStr = ' ';
let nonUnique = ' ';
for (let i = 0; i < string.length; i++){
if(uniqueStr[i] !== string[i]){
uniqueStr += string[i];
} else if (string[i]== string[i]){
nonUnique += string[i];
}
}
console.log(uniqueStr);
}

isUnique('Goodbyee')

// Issue is that it catches a nonUniqe and stores it only once
// Ex: Goodbyee turns into Godbyee
//Try to figure out why that is

//Incrementing (++) won't work. Re-ordering of test statements doesn't work.
19 changes: 18 additions & 1 deletion largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@
* 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.
*/
*/


const checkForPrimePalindrome = (num) => {
num = num + '';
let reverseNum = num.split("").reverse().join("");
if(reverseNum === num){
if(reverseNum % num === 0){
return true;
} else if (reverseNum === 0 || reverseNum === 1 ) {
return false;
}
}
return false;
}


console.log(checkForPrimePalindrome(929));
Loading