Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
13228e1
lomgestString commit by Allan T.
allanv2k Aug 8, 2017
7298de4
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 9, 2017
30c547f
Code Challenge commit 9UG
allanv2k Aug 9, 2017
db32535
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 10, 2017
faa622a
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 11, 2017
584fabc
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 14, 2017
5dc0e74
removeDuplicates coding challenge commit 14UG
allanv2k Aug 14, 2017
354f9cf
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 15, 2017
1d02ef1
Coding Challenge commit 15UG
allanv2k Aug 15, 2017
3f3d6cd
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 16, 2017
b6de972
Coding Challenge commit 16UG #HalaMadrid
allanv2k Aug 16, 2017
62a5181
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 17, 2017
5b774d9
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 18, 2017
2fa3c85
Coding Challenge commit 18AUG
allanv2k Aug 18, 2017
ec09784
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 21, 2017
7c79248
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 22, 2017
502edf7
Coding Challenge commit 22AUG
allanv2k Aug 22, 2017
911f908
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 23, 2017
531c524
Coding Challenge commit 23AUG
allanv2k Aug 23, 2017
3926067
Merge branch 'master' of https://github.com/LambdaSchool/CS2-Code-Cha…
allanv2k Aug 24, 2017
08975c6
Coding Challenge commit 24AUG
allanv2k 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
1 change: 1 addition & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
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 three-quart jug, pour it into the five-quart jug. Then fill the three-quart jug again and fill the five-quart jug until it is full (leaving one-quart left in the three-quart jug). Throw away the five-quart jug, then pour your remaining one-quart into the five-quart jug, then fill the three-quart jug and add it to the one-quart in the three-quart jug.
8 changes: 5 additions & 3 deletions callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* For today's coding challenge your job is to write functions
* so that each function call works.
*
* Example:
*
* greeting('Hey guys', (message) => {
Expand All @@ -12,10 +11,8 @@
* const greeting = (str, cb) => {
* cb(str);
* };
*
*/


// 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'];
Expand All @@ -24,6 +21,11 @@ firstItem(foods, (firstItem) => {
console.log(`The first item is ${firstItem}.`);
});

const first = (foods, callback) => {
ccallback(foods[0]);
};
console.log()

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

getLength(foods, (length) => {
Expand Down
8 changes: 7 additions & 1 deletion commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/*
* Common Characters:
* Write a function that accepts two strings as arguments, and returns only the characters that are common to both strings. *
* Write a function that accepts two strings as arguments, and returns only the characters that are common
* to both strings. *
* Your function should return the common characters in the same order that they appear in the first argument.
* Do not return duplicate characters and ignore whitespace in your returned string. *
* Example: commonCharacters('acexivou', 'aegihobu') *
* Returns: 'aeiou'
*/
function commonCharacters (char1, char2) {

}
return commonCharacters;
console.log(commonCharacters(arre, ace));
39 changes: 38 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,41 @@
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/
* this.value = [Humanoid, Animal, Plant];
this.Humanoid = [Human, Elf, Orc];
this.Animal =[Bear, Wolf];
this.Plant = [FleshEatingDaisy];
*/

class NPC {
constructor(value) {
this.value = value;
this.children = [];
}
class Humanoid {
constructor(value) {
this.value = value;
this.children = [Human, Elf, Orc];
}
}
class Animal {
constructor(value) {
this.value = value;
this.children = [Bear, Wolf];
}
}
class Plant {
constructor(value) {
this.value = value;
this.children = [FleshEatingDaisy];
}
}
class Human {
constructor(value) {
this.value = value;
this.children = [Soldier, Peasant, Bandit];
}
}


} // end of class NPC
23 changes: 20 additions & 3 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@
* * const onlyEven = evenOccurance([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]);
* * console.log(onlyEven); // 4
* */
const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]);
const evenOccurence = (array) => {

// first: let's count occurences of all the elements in the array
let hash = {}; // object to serve as counter for all the items in the array (the items
// will be the keys, the counts will be the values)
array.forEach(function(e) { // for each item e in the array
if(hash[e]) hash[e]++; // if we already encountered this item, then increments the counter
else hash[e] = 1; // otherwise start a new counter (initialized with 1)
});
};

const evenOccurence = (arr) => {
// Your code here.
};
// second: we select only the numbers that occured an odd number of times
let result = []; // the result array
for(var e in hash) { // for each key e in the hash (the key are the items of the array)
if(hash[e] % 2 === 0) // if the count of that item is an even number
result.push(+e); // then push the item into the result array (since they are keys are strings we have to cast them into numbers using unary +)
}
return result;
}
console.log(onlyEven);
27 changes: 26 additions & 1 deletion forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,36 @@
// See if you can solve this with just ES5 JS.
// The output should be 1, 2, 3, .... 10. Right now it just prints 11.
// 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);
}
*/
for (i = 1; i <= 10; i++) {
setPrint(i);
}

function setPrint(i) {
setTimeout(function() {
console.log(i);
});
}
// ES6
for (let h = 1; h <= 10; h++) {
setTimeout(function() {
console.log(h);
}, 0);
}
//

for (var i = 1; i <= 10; i++) {
(function(i) {
setTimeout(function() {
console.log(i);
}, 0);
})(i);
}
15 changes: 14 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/
const checkStr = (uniqueString) => {
const str = {};
for (let i = 0; i < uniqueString.length; i++) {
const check = str[i];
if (uniqueString[check])
return false;
else uniqueString[check] = true;
}
return true;
}
//test
console.log(checkStr("abddefg")); //true
console.log(checkStr("aa")); //false
58 changes: 57 additions & 1 deletion largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,60 @@
* 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 largestPrimePalindrome(num) {

for (i = 0; i <= num; i++) {
// Look for all primes within 1000
var prime = function () {
var num;
for (num = 0; num < 1001; num++)
if (num % 2 === 0){
break;
}
else if (num % 3 === 0){
break;
}
else if (num % 4=== 0){
break;
}
else if (num % 5 === 0){
break;
}
else if (num % 6 === 0){
break;
}
else if (num % 7 === 0){
break;
}
else if (num % 8 === 0){
break;
}
else if (num % 9 === 0){
break;
}
else if (num % 10 === 0){
break;
}
else if (num % 11 === 0){
break;
}
else if (num % 12 === 0){
break;
}
else {
return num;
}
}
};
//return prime;
console.log(prime(1000));

}
// check those primes to see which one is a palindrome

// }

//return largestPrimePalindrome(1000);
//console.log(largestPrimePalindrome);
28 changes: 28 additions & 0 deletions longestString/longestString.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,31 @@
* Write a function that accepts an array of strings.
* Return the longest string in the array.
*/
/*
* Write a function that accepts an array of strings.
* Return the longest string in the array.
*/

// 1. identify test cases
// ['house', 'boat', 'cat'] -> 'house'
// ['abc', 'def'] -> 'def'
// [] -> null

/*
function longestString strings
loop over the array of strings
do something in the loop
return longestString

const longestString = (strings) => {

};
*/

const longestString ['house', 'boat', 'cat'] => {
const longestString.forEach(function(item, index, array) {
console.log(item, index);
});

}

31 changes: 28 additions & 3 deletions removeDuplicates/removeDuplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,32 @@
* So if you're using 'indexOf' 'sort' 'forEach' etc,
* you're more than likely using a for loop under the hood.
*/

const arr = [1, 1, 1, 2, 2, 3, 4, 5, 5];
const removeDuplicates = (arr) => {
//code here...
};
//array
const nonDuplicates = new Set();
nonDuplicates.forEach((nonDup, i) => {
if (nonDup === nonDup) {
nonDuplicates[i] = nonDup();
} else {
nonDuplicates[i] = nonDup();
}
});
return nonDuplicates;
};

console.log(removeDuplicates(arr));

/*
const removeDuplicates = (arr, cb) => {
const set = new Set();
arr.forEach(item => {
set.add(item);
});
cb(Array.from(set));
};

removeDuplicates(foods, (uniqueFoods) => {
console.log(`foods with duplicates removed: ${uniqueFoods}`);
});
*/
16 changes: 15 additions & 1 deletion reverseCase/reverseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
* Write a function that reverses the case of each letter in the strings that it receives.
* Example: 'Hello World' -> 'hELLO wORLD'
* Assume that each string will contain only spaces and letters.
*/

const swapCase = (word) => {
let swap = " ";
for (let i=0; i < word.length; i++) {
const str = word.charAt(i);
swap += (str == str.toUpperCase() ? str.toLowerCase() : str.toUpperCase());
// console.log(str);
}
}
return swap;
};
const swapper = swapCase('Hello');
console.log(swapper);
*/

30 changes: 30 additions & 0 deletions stringCompression/stringCompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,33 @@
// If the "compressed" string would not become smaller than the original string,
// your method should return the original string.
// You can assume the string has only uppercase and lowercase letters (a - z).

const stringCompression = (str) => {
let arr = [];
// let count =[];

str.split('').forEach((letter) => {
if (str.split('').includes(letter) && !arr.includes(letter)) {
arr.push(letter);
}

// Now, if I have the letters, use RegExp or match to get the count


});

return arr.join('').replace(str);
}

console.log(stringCompression('aaabbccc'));

const stringSearch = (str) => {
for (let count =- 1, index =- 2; index != 1;
count++, index = str.indexOf(stringSearch, index + 1)
);
}

return str;
console.log(stringSearch('aaabbb'));


7 changes: 7 additions & 0 deletions vowelCount/vowelCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
* Write a function that returns the count of the total number of vowels in a string.
* Example: 'Hello World!' -> 3
*/

const vowelCount = str =>
Array.from(str)
.filter(vowel => 'aeiou'.includes(vowel)).length;


console.log(vowelCount('hello')); // 2