Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0a35117
finished the code challenge
jeshsy Jul 10, 2017
d386184
added line to end of code
jeshsy Jul 10, 2017
bb47aa0
changing a typo on line 13 semicolon instead of colon
jeshsy Jul 10, 2017
01db91f
finished isUnique
jeshsy Jul 11, 2017
2e384f1
working on the problem
jeshsy Jul 12, 2017
ad8e14c
added comment on what to do to fix my not working code
jeshsy Jul 12, 2017
0c55754
got reversecase to work
jeshsy Jul 13, 2017
dd873c8
committing cause i cant pull
jeshsy Jul 14, 2017
fba0e8d
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 14, 2017
471b5cf
got evenoccurences to work but not largest prime palindrome
jeshsy Jul 14, 2017
d351855
got largest primepalindrome to work
jeshsy Jul 14, 2017
35e8f37
comment out the test
jeshsy Jul 14, 2017
61e3c39
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 17, 2017
badbcd1
finished some of forlooptimeout
jeshsy Jul 19, 2017
f062901
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 19, 2017
c9ff45b
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 20, 2017
668eb25
finished brainteaser
jeshsy Jul 20, 2017
94091de
fixed brainteaster
jeshsy Jul 20, 2017
2d963f7
found my binary search file and realized my error: arr[1.5] wont work
jeshsy Jul 20, 2017
a79d764
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 21, 2017
db0474c
array isnt completely worknig
jeshsy Jul 24, 2017
a098618
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
jeshsy Jul 24, 2017
8b5daab
got string compression to work
jeshsy Jul 24, 2017
7161dfb
finished operators
jeshsy Jul 25, 2017
a2daedd
commented out test
jeshsy Jul 25, 2017
6b86f2e
nothing change
jeshsy Jul 25, 2017
abee72c
nothing changed
jeshsy Jul 25, 2017
e5609e6
added a few classes
jeshsy Jul 27, 2017
75fc4f0
dont understand what was asked in queuestack
jeshsy Jul 28, 2017
446ff2d
finished bubble sort
jeshsy Jul 28, 2017
02fbb2c
did not get real far with allAnagrams
jeshsy Aug 1, 2017
2cf3ade
finished insertionSort
jeshsy Aug 1, 2017
449ec48
completed rotateImage
jeshsy Aug 2, 2017
69633a1
finished logicGates
jeshsy Aug 3, 2017
6a0362b
rotateimage
jeshsy Aug 7, 2017
c27f49c
not quite done with rps
jeshsy Aug 8, 2017
e143aef
rps fixed
jeshsy Aug 8, 2017
2a06908
got rps to work
jeshsy Aug 9, 2017
b52d236
finished selection sort
jeshsy Aug 9, 2017
7896685
???
jeshsy Aug 14, 2017
4e36173
didnt know what bluesquares wanted. also jquery???
jeshsy Aug 15, 2017
3261801
minor changes
jeshsy Aug 16, 2017
7d857b6
not done
jeshsy Aug 18, 2017
f8a1f41
not quite done
jeshsy Aug 22, 2017
79e6866
zzz
jeshsy Aug 24, 2017
510cac0
finished vowelCount without y
jeshsy Aug 24, 2017
e734041
finished meanmedianmode
jeshsy Aug 28, 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
23 changes: 22 additions & 1 deletion allAnagrams/allAnagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@
* example usage:
* const anagrams = allAnagrams('abc');
* console.log(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ]
*/
*/

// thoughts. probably going to split that string up into single characters.
// maybe use set to get rid of dupes
// permutations, but i dunno how to write this
// time complexity of n!, which is actually the worst
// recursion? I have to stop attempting making everything with recursion.
// legit first thought was recursion. stahpw
// can stop after string gets completely reversed(maybe multiple of same character might break this)


const allAnagrams = (word) => {
arr = [word];
if (word.length < 2) return arr;
splitChars = word.split('');
const recurseAnagrams = () => {
for (let i = 0; i < splitChars.length; i++) {

}
}
return arr;
}
20 changes: 20 additions & 0 deletions array/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@
* How do these operations compare to that of a linked list?
* How does the time complexity of insertion and deletion compare to that of a linked list?
*/

class Array {
constructor() {
this.indicator = 0;
this.array = {};
}
push(value) {
this.array[indicator] = value;
this.indicator ++;
}
pop() {

}
get(index) {

}
delete(index) {

}
}
18 changes: 16 additions & 2 deletions binarySearch/binarySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,19 @@
**/

const binarySearch = (nums, target) => {

};
let min = 0;
let max = nums.length;
const search = () => {
if(nums[max / 2] > target) {
max = max / 2 - 1;
search();
}
if(nums[max / 2] < target) {
min = max / 2 + 1;
search();
}
if(nums[max / 2] === target) {
return max / 2;
}
};
};
11 changes: 11 additions & 0 deletions blueSquares/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>

</body>
</html>
Empty file added blueSquares/script.js
Empty file.
Empty file added blueSquares/styles.css
Empty file.
5 changes: 5 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
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.

measure the 5, pour into the 3 to get 2 quarts remaining in the 5 quart. Do this twice.

Apparently you can't do that, as you dont have any other sort of containers.
So you pour 3 qt into the 5 twice. 5 qts in the 5 and 1 in the 3. Dump the 5, pour the 1 qt into the 5 container, and then pour 3 more into it to get the 4.
19 changes: 19 additions & 0 deletions bubbleSort/bubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,24 @@
*/

const bubbleSort = (arr) => {
if (arr === null) return null;
let sorted = false;
while (sorted === false) {
let counter = 0;
for (let i = 1; i < arr.length; i++) {
if (arr[i - 1] > arr[i]) {
let temp = 0;
temp += arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
sorted = false;
counter += 1;
}
}
if (counter === 0) sorted = true;
}
return arr;
//code here
};

console.log(bubbleSort([2, 1, 3, 2, 1, 11, 4, 1, 4, 7, 12, 5]));
32 changes: 32 additions & 0 deletions callbackPractice/callbackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,83 @@

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, i, cb) => {
cb(arr.includes(i));
}

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) => {

}

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) => {
for (let i = 0; i < arr.length; i++) {

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

const commonCharacters = (a, b) => {

}
41 changes: 40 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,43 @@
*
* 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.str = options.str;
this.def = options.def;
this.spd = options.spd;
}
}

class Humanoid extends NPC {
constructor(options) {
super(options);
this.job = options.job;
}
}

class Human extends Humanoid {
constructor(options) {
super(options);
this.race = options.race;
}
}

class Soldier extends Human {
constructor(options) {
super(options);
this.hp += 10;
};
}

const jeff = new Soldier({
hp: 10,
str: 10,
def: 10,
spd: 10,
job: 'Baker'
});
console.log(jeff);
14 changes: 14 additions & 0 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,19 @@
* */

const evenOccurence = (arr) => {
const checker = new Set();
let answer = [];
let temp = 0;
for (let i = 0; i < arr.length; i++) {
checker.add(arr[i]);
if (checker.size === temp) answer.push(arr[i]);
// console.log('size',checker.size, 'temp', temp, 'bool', checker.size === temp);
temp += 1;
}
if (answer.length === 0) return null;
return answer[0];
// Your code here.
};

const tester = [1,2,2,22,3,44,23,12,22,4];
console.log(evenOccurence(tester)); //should be 22
12 changes: 11 additions & 1 deletion insertionSort/insertionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
// insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8]); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9]

const insertionSort = (array) => {
for (let i = 1; i < array.length; i++) {
for (let j = 0; j < i; j++) {
if(array[i] < array[j]) {
let removed = array.splice(i, 1);
array.splice(j, 0, removed[0]);
}
}
}
// Your code goes here. Feel free to add helper functions if needed.
return array;
};
};

console.log(insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8]));
6 changes: 6 additions & 0 deletions isUnique/isUnique.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
*/

const isUnique = (str) => {
const tester = str.split("").sort();
let check = true;
for (let i = 1; i < tester.length; i++) {
if (tester[i] === tester[i-1]) check = false;
}
return check;

};

Expand Down
27 changes: 27 additions & 0 deletions largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,30 @@
* Extra credit: Modify the function to look for the largest prime palindrome less than any provided number.
* Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes)
*/
const isPalindrome = (suspect) => {
// checks to see if it's a palindrome
// turns int to str, then splits into array of 1 letter characters
// then reverses this array, and joins it back to a string
// then turns this reversed string back into an int, and checks if the two are equal
if (suspect === parseInt(suspect.toString().split('').reverse().join(''), 10)) return true;
return false;
}

const isPrime = (suspect) => {
if (suspect === 1) return false;
else if (suspect === 2) return true;
for (let j = 2; j < suspect; j++) {
if (suspect % j === 0) return false;
}
return true;
}

const largestPP = (limit) => {
const PParray = [];
for (let i = 1; i < limit; i++) {
if (isPalindrome(i) && isPrime(i)) PParray.push(i);
}
return PParray.pop();
}

// console.log(largestPP(1000));
9 changes: 9 additions & 0 deletions logicGates/logicGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@

const NAND = (x, y) => {
// You can use whatever JS operators that you would like: &&, ||, !
let temp = !(x && y);
if (temp === true) return 1;
return 0;
};

const NOT = (n) => {
return NAND(n, n);
// Do not use !, &&, or ||
};

const AND = (x, y) => {
return NOT(NAND(x, y));
// Do not use &&, ||, or !
// You can use any of the functions that you have already written
};

const OR = (x, y) => {
return NAND(NAND(x, x), NAND(y, y));
// so it'll be false if x is true and same for y
// so if either are false, nand will pull out true
// Do not use ||, &&, or !
// You can use any of the functions that you have already written
};

const XOR = (x, y) => {
AND(OR(x, y), NAND(x, y));
// Do not use ||, &&, or !
// You can use any of the functions that you have already written
};
4 changes: 4 additions & 0 deletions longestRun/longestRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
* Input: "abcdefgh" Output: [ 0, 0 ]
* Input: "aabbbcccc" Output: [ 5, 4 ]
*/

const longestRun = (str) => {
let arr = [0, 0];
}
Loading