Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5598dff
longestString\longestString.js
rolandc5 Aug 8, 2017
a03bc79
longestString\longestString.js
rolandc5 Aug 8, 2017
3512a41
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 9, 2017
4b88120
reverseCase\reverseCase.js
rolandc5 Aug 9, 2017
4b2c67d
Update reverseCase.js
rolandc5 Aug 9, 2017
dd999fa
reverseCase\reverseCase.js
rolandc5 Aug 9, 2017
c773057
Merge https://github.com/rolandc5/CS2-Code-Challenges
rolandc5 Aug 9, 2017
96aa4d4
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 10, 2017
81bf123
isUnique\isUnique.js
rolandc5 Aug 10, 2017
218f005
isUnique\isUnique.js
rolandc5 Aug 10, 2017
d4c2b69
isUnique\isUnique.js
rolandc5 Aug 10, 2017
df8b8ba
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 11, 2017
3320b81
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 14, 2017
03bffd5
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 15, 2017
d517fd6
brainTeasers\waterJugs.md
rolandc5 Aug 15, 2017
57063ff
brainTeasers\waterJugs.md
rolandc5 Aug 15, 2017
361c246
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 17, 2017
02bcbdc
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 18, 2017
bbe9330
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 21, 2017
571ce1c
complete
rolandc5 Aug 21, 2017
6c8a6c5
complete
rolandc5 Aug 21, 2017
d2d0589
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
rolandc5 Aug 22, 2017
0fc0b77
update
rolandc5 Aug 23, 2017
a840d25
update
rolandc5 Aug 23, 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
15 changes: 15 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
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.

1 five quart jug
1 three quart jug

needs 4 quarts of water

can't fill the water up exactly half

Fill up the five-quart jug with 3 quarts of water and fill the three-quart jug with 1 quarts of water.
You will get exactly 4 quarts of water.

Step 1: Fill the 5 quarts pour all of the water inside the 3 quarts jug
Step 2:

does not say we can't go over half of the jug. Just says having exactly half is impossible.
54 changes: 36 additions & 18 deletions callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,73 @@


// Write a function called firstItem that passes the first item of the given array to the callback function

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

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

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

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

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

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

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


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

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

multiplyNums(5, 10, (product) => {
const multiplyNums = (5, 10, (product) => {
product = 5 * 10;
console.log(`The product is ${product}.`);
});
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) => {
const contains = (foods, 'ribeye', (result) => {
for (let i = 0; i < foods.length; i++) {
if (foods[i] === 'ribeye'){
result = foods[i];
}//if
}//for
console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array');
});
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.
const removeDuplicates = (foods, (uniqueFoods) => {
let newFoods = [];
for (let i = 0; i < foods.length; i++) {
newFoods[i] = foods[i];
}
uniqueFoods = newFoods.slice(1,2);
console.log(uniqueFoods)

removeDuplicates(foods, (uniqueFoods) => {
console.log(`foods with duplicates removed: ${uniqueFoods}`);
});
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) => {
const forEach = (foods, (value, index) => {
for (let i = 0; i < foods.length; i++) {
value(foods[i], index);
}
console.log(`${value} is at index ${index}.`);
});
});
forEach();
40 changes: 40 additions & 0 deletions commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,43 @@
* Example: commonCharacters('acexivou', 'aegihobu') *
* Returns: 'aeiou'
*/
/*
const commonChar = (str1, str2) => {
let string = [];
if (str1.indexOf('a') > -1 && str2.indexOf('a') > -1) {
string.push('a');
}
if (str1.indexOf('e') > -1 && str2.indexOf('e') > -1) {
string.push('e');
}
if (str1.indexOf('i') > -1 && str2.indexOf('i') > -1) {
string.push('i');
}
if (str1.indexOf('o') > -1 && str2.indexOf('o') > -1) {
string.push('o');
}
if (str1.indexOf('u') > -1 && str2.indexOf('u') > -1) {
string.push('u');
}
return string.join('');
}

const str1 = 'areyiwoqu';
const str2 = 'asedifogu';

console.log(commonChar(str1, str2));
*/


const commonChars = (str1, str2) => {
let common = [];


str1.split('').forEach((letter) => {
if (str2.split('').includes(letter) && !common.includes(letter)) {
common.push(letter);
}
});
return common.join('').replace(' ', '');
}
console.log(commonChars('axei ou', 'aeidou'));
74 changes: 73 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,76 @@
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/
*/

class NPC {
constructor() {
this.humanoid = [];
this.animal = [];
this.plant = [];
}
humanoidClass(selectClass) {
const humanoidClass = [`human`, 'Elf', 'Orc'];
let selectedHumanClass = humanoidClass[selectClass];
if (selectedHumanClass === `human`) {
class Stats {
constructor() {
this.hp = 125;
this.stregnth = 2;
this.agility = 3;
this.mana = 5;
}
}
const stats = new Stats();
this.humanoid.push(selectedHumanClass, new Stats);
}
if (selectedHumanClass === 'Elf') {
class Stats {
constructor() {
this.hp = 125;
this.stregnth = 2;
this.agility = 3;
this.mana = 5;
}
}
this.humanoid.push(selectedHumanClass, new Stats);
}
if (selectedHumanClass === 'Orc') {
class Stats {
constructor() {
this.hp = 200;
this.strength = 5;
this.agility = 4;
this.mana = 0;
}
}
this.humanoid.push(selectedHumanClass, new Stats);
}
}
animalClass(selectClass) {
const animalClass = ['Bear', 'Wolf'];
let selectedAnimalClass = animalCLass[selectClass];
if (selectedAnimalClass === 'Bear') {
class Stats {
constructor() {
this.hp = 1000;
this.strength = 6;
this.agility = 4;
this.mana = 0;
}
}
this.animal.push(selectedAnimalClass, new Stats);
}
}
plantClass(selectClass) {
const plantClass = ['Flesh Eating Daisy'];
this.animal.push(plantClass[selectClass]);
}
}

const npc = new NPC();
npc.humanoidClass(0);
//npc.humanoidClass(1);
//npc.humanoidClass(2);
console.log(npc.humanoid);

18 changes: 17 additions & 1 deletion evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
* * console.log(onlyEven); // 4
* */


const evenOccurence = (arr) => {
// Your code here.
let arrStorage = {};

arr.forEach = (value) => {
arrStorage[value] = storage[value] + 1 || 1;
};

for (let i = 0; i < arr.length; i++) {
let even = arr[i];

if (arrStorage[even] % 2 === 0) {
return even;
}
}
return null;
};

const randomArray = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]);
4 changes: 1 addition & 3 deletions forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

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++);
}, 0);
}
74 changes: 73 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/

/*
let isUnique = string => {
unique: 'Hello'
unique1: 'Hi'
unique2: 'This'
};

if (isUnique < 100) {
console.log('this does not have unique char');
} else
console.log('This has unique char');
console.log(isUnique);

switch (isUnique()) {
case (isUnique.unique): {
console.log('char hello');
}
case(isUnique.unique1): {
console.log('char hi');
}
case(isUnique.unique2): {
console.log('char this');
break;
}
console.log('No other char');
}
console.log('Program ending');

*/

/*
function isUnique structures
iterate over str
iterate over str starting at i + 1
if we find a match return false
return true;
*/

/*
const isUnique = (str) => {
for (let i = 0; i < str.length; i++) {
for (let j = i + 1; j < str.length; j++) {
if (str[i] === str[j]) return false;
}
}
return true;
};
const str1 = 'abcdefg';
const str2 = 'abcdefgg';
const result = isUnique(str1);
console.log(result);
*/



const isUnique = (str) => {
const set = new Set();
for (let i = 0; i < str.length; i++) {
const character = str[i];
const isInSet = set.has(character);
if(isInSet) return false;
if (!isInSet) set.add(character);
}
return true;
};
const str1 = '1234567890qwertyuiopasdfghjklzxcvbnm';
const str2 = 'abcdefgg';

const result = isUnique(str1);

console.log(result);
22 changes: 21 additions & 1 deletion largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@
* 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 largestPrimePalindrome = () => {

const isPalindrome = (n) => {
if (n === n.toString().split(''.reverse().join(''))) return true;
}
const isPrime = (n) => {
if (n % 2 === 0) {
for (let j = 3; j <= Math.sqrt(n); j++) {
if (n % k === 0) return false;
}
return true;
}
}

for (let i = 1000; i > 0; i--) {
if (isPalindrome(i) && isPrime(i)) return i;
}
}
Loading