Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0da7e56
finished challenges
Jul 12, 2017
12c59d7
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 12, 2017
f7cf959
finished reverseCase
Jul 13, 2017
4578cee
marging changes
Jul 16, 2017
0c09110
finished largestPrimePalindrome
Jul 17, 2017
b1527a2
finished evenOccurences
Jul 17, 2017
135eee5
finished challenge
Jul 17, 2017
c0fb404
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 18, 2017
64eed4c
finished forLoopTimeout
Jul 19, 2017
a5fc416
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 20, 2017
76c3bb4
finished binary search
Jul 20, 2017
2820848
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 20, 2017
778e1b6
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 21, 2017
c594601
array.js update
Jul 21, 2017
7c7010b
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 24, 2017
190f7e0
finished arrray
Jul 25, 2017
33b2a33
finished stringCompression
Jul 25, 2017
35aa5f4
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 25, 2017
52ac133
updated solution
Jul 25, 2017
46d5114
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 26, 2017
597dbdd
updated solutions
Jul 27, 2017
889b320
updated file
Jul 27, 2017
48c7a38
challange progress
Jul 28, 2017
7879ef2
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Jul 31, 2017
ccb16f3
complered challenges
Jul 31, 2017
56c4f29
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 1, 2017
da34150
finished challenge
Aug 2, 2017
b4eb306
finished challenge
Aug 2, 2017
9a5fab9
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 2, 2017
9f9dbd5
completed rotateImage
Aug 3, 2017
a7dfae4
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 3, 2017
a2487c0
logicGates progress
Aug 4, 2017
8ab6104
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 4, 2017
f9f77e2
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 7, 2017
a726987
finished parallel
Aug 8, 2017
bd00968
finished rockPaperScissors
Aug 8, 2017
c22bc29
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 8, 2017
ee5e840
finished quickSort
Aug 8, 2017
adaca0c
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 9, 2017
4d1870b
finished selectionSort
Aug 9, 2017
4ca9d5c
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 11, 2017
97ed2df
linkedListCycle progress
Aug 11, 2017
7f79177
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 14, 2017
35f43cb
finished challenge
Aug 14, 2017
f305a40
finished challenge
Aug 15, 2017
3aa94a4
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 15, 2017
8ad33bd
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 16, 2017
177465e
finished challenge
Aug 16, 2017
196611b
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 17, 2017
12712c9
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 18, 2017
a42ab54
finished challenge
Aug 18, 2017
1f27ffe
not finished
Aug 18, 2017
29ab0f1
not finished
Aug 18, 2017
751fd98
finished challenge, go over solution
Aug 18, 2017
673b0d5
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 21, 2017
ccfa367
working on tests
Aug 21, 2017
825839e
not finished
Aug 23, 2017
2be3575
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 23, 2017
f2cea87
completed challenge
Aug 23, 2017
d33a6b9
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 24, 2017
370d169
challenge completed, go over solution
Aug 25, 2017
87e626c
finished challenge
Aug 25, 2017
afc439f
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
Aug 25, 2017
e0c167a
completed challenge
ely-alamillo Oct 4, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 14 additions & 1 deletion allAnagrams/allAnagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@
* example usage:
* const anagrams = allAnagrams('abc');
* console.log(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ]
*/
*/

const allAnagrams = (str, start = '') => {
if (str.length === 1) return [start + str];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should indent these lines inside of a function block.

const anagrams = [];

for (let i = 0; i < str.length; i++) {
const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]);
for (let j = 0; j < result.length; j++) {
anagrams.push(start + result[j]);
}
}
return anagrams;
};
36 changes: 36 additions & 0 deletions array/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,39 @@
* 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.array = {};
this.key = 0;
}
push(value) {
this.array[this.key] = value;
this.key += 1
}
pop() {
const value = this.array[this.key - 1];
delete this.array[this.key - 1];
this.key -= 1;
return value;
}
get(index) {
//console.log(index);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code.

return this.array[index];
}
delete(index) {
delete this.array[index];
for (let i = index; i < this.key; i++) {
this.array[i] = this.array[i + 1];
}
this.key--;
}
}

const a = new Array();
a.push(5);
a.push(53);
a.push(54);
console.log(a);
a.delete(0);
console.log(a);
13 changes: 13 additions & 0 deletions binarySearch/binarySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@
**/

const binarySearch = (nums, target) => {
let high = nums.length - 1;
let low = 0;
let middle;

while (low < high) {
middle = Math.floor((low + high) / 2);
if (target === nums[middle]) return middle;
else if (target > nums[middle]) {
low = middle + 1;
} else {
high = middle - 1;
}
}
return 'not found';
};
14 changes: 0 additions & 14 deletions blueSquares/blueSquares.md

This file was deleted.

6 changes: 6 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
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.

i would fill both the 3 and 5 quart jugs at the same time and stop the water flow when the 3
quart jug is full. Now the 5 quart jug has 3 quarts and the 3 quart jug is filled. Then, i will pour
out the 3 quart jug in the 5 quart jug until it is filled. Now my 3 quart jug is left with 1 quart. Now
i empty the 5 quart jug and pour the 1 quart from the 3 quart jug. Finally, i will fill the 3 quart jug
and then pour it in the 5 quart jug that currently has one quart and i will end up with 4 quarts in the 5 quart jug.
14 changes: 13 additions & 1 deletion breadthFirstSearch/breadthFirstSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@
* a: 2,
* };
* breadthFirstSearch(tree, 2);// will return true before it recursively searches `z`
*/
*/

const breadthFirstSearch = (tree, searchTerm) => {
let queue = Object.values(tree);
while (queue.length > 0) {
value = queue.shift();
if (value === searchTerm) return true;
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
queue = queue.concat(Object.values(value));
}
}
return false;
};
18 changes: 18 additions & 0 deletions bubbleSort/bubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@

const bubbleSort = (arr) => {
//code here
const bubbleSort = (arr) => {
let swappedValue;
do {
swappedValue = false;
for (let i = 0; i < arr.length; i++) {
console.log(arr);
if (arr[i] > arr[i + 1]) { // [2, 1, 3]
let temp = arr[i]; // temp = 2
arr[i] = arr[i + 1]; // [1, 1, 3] temp = 2;
arr[i + 1] = temp; // [1, 2, 3];
swappedValue = true;
}
}
} while (swappedValue);
return arr;
};

console.log(bubbleSort([5, 6, 7, 3, 2, 1])); // returns [1, 2, 3]
};
41 changes: 34 additions & 7 deletions callbackPractice/callbackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,79 @@
// 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'];
const firstItem = (arr, cb) => {
return 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) => {
return 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 = (x, y, cb) => {
cb(x + y);
};
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 = (x, y, cb) => {
return cb(x * y);
};
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, item, cb) => {
return cb(arr.includes(item));
};
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) => {
// const set = new Set(arr);
// console.log(set);
// return cb(set);
// };
const removeDuplicates = (arr, cb) => {
const newArray = arr.filter((item, index, inputArray) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of Filter here! It's one of my favorite JS methods. Any chance you could try and solve this without using it?

return inputArray.indexOf(item) === index;
});
cb(newArray);
};
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++) {
cb(arr[i], i);
}
};
forEach(foods, (value, index) => {
console.log(`${value} is at index ${index}.`);
});
34 changes: 29 additions & 5 deletions commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
/**
* Common Characters:
* 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') *
* Common Characters:
* 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'
*/

const eliminateWhitespace = (str) => {
const re = /\s/g;
str = str.replace(re, '');
return str;
};

const commonCharacters = (str1, str2) => {
const uniqueCharacters = new Set();
str1 = eliminateWhitespace(str1);
str2 = eliminateWhitespace(str2);
str1 = str1.split('');

for (let i = 0; i < str1.length; i++) {
if (str2.includes(str1[i])) {
uniqueCharacters.add(str1[i]);
}
}
const commonLetters = Array.from(uniqueCharacters).join('');
return commonLetters;
};

let str1 = 'acex ivou';
const str2 = 'aegihobu';
console.log(commonCharacters(str1, str2)); // --> 'aeiou'
53 changes: 52 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,55 @@
*
* 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.power = options.power;
this.speed = options.speed

}
delete() {
`${this.name} has been removed from the game`;
}
}

class Humanoid extends NPC {
constructor(options) {
super(options);
this.name = options.name;
this.height = options.height;
this.gender = options.gender;
}
walk() {
`${this.name} is walking`;
}
}

class Human extends Humanoid {
constructor(options) {
this.language = options.language;
this.liniage = options.liniage;
}
talk() {
`${this.name} is talking ${this.language}`
}
}

class Elf extends Humanoid {
constructor(options) {
this.clan = options.clan;
}
shootBow() {
`${this.name} shot a bow!`;
}
}

class Orc extends Humanoid {
constructor(options) {
this.tribe = options,tribe;
}
swingSword() {
`${this.name} swung a sword!`;
}
}
23 changes: 20 additions & 3 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
* * console.log(onlyEven); // 4
* */

const evenOccurence = (arr) => {
// Your code here.
};
const evenOccurence = (arr) => {
// Your code here.
let numberStorage = {};
arr.forEach((number) => {
if (numberStorage[number]) {
numberStorage[number] = numberStorage[number]+1
} else {
numberStorage[number] = 1;
}
})
for (let i = 0; i < arr.length; i++) {
let currentNumber = arr[i];
if (numberStorage[currentNumber] % 2 === 0) {
return currentNumber;
}
}
return null;
};
const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]);
console.log(onlyEven);
14 changes: 0 additions & 14 deletions fizzBuzzTesting/fizzBuzz.js

This file was deleted.

Loading