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
764a8e4
completed longestString challenge
loyslane Jul 10, 2017
d52b11d
Add files via upload
loyslane Jul 11, 2017
0eaffca
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 11, 2017
10cbc96
completed isUnique challenge
loyslane Jul 12, 2017
7947fce
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 12, 2017
156cc6a
completed reverseCase.js
loyslane Jul 13, 2017
a6abbf7
revised reverseCase.js
loyslane Jul 13, 2017
e6c3793
merging updated files
loyslane Jul 14, 2017
6da704e
completed largestPrimePalindrome challenge
loyslane Jul 14, 2017
c7061ce
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 14, 2017
25df4c6
completed evenOccurences challenge
loyslane Jul 17, 2017
b8bff7e
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 17, 2017
e75251f
completed callbackPractice challenge
loyslane Jul 18, 2017
b46a6bc
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 18, 2017
8d25dc7
possibly figured out forLoopTimeout.js
loyslane Jul 18, 2017
faad524
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 19, 2017
b2a4072
completed binarySearch challenge
loyslane Jul 20, 2017
d0971c5
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 20, 2017
6021719
completed waterJugs challenge
loyslane Jul 20, 2017
cfd76f9
updated binarySearch solution
loyslane Jul 20, 2017
c1fe590
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 21, 2017
9302500
udated array.js -work in progress
loyslane Jul 24, 2017
69088a3
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 24, 2017
65338ea
completed stringCompression challenge
loyslane Jul 25, 2017
be226b5
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 25, 2017
a17ec8a
completed operators challenge
loyslane Jul 25, 2017
a4c2bdb
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 26, 2017
148dcce
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 27, 2017
bc8e3cd
completed queueStack challenge
loyslane Jul 28, 2017
e188e84
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 28, 2017
bd60fce
completed bubbleSort challenge
loyslane Jul 28, 2017
69f9049
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Jul 31, 2017
ede205e
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 1, 2017
f573bbf
completed insertionSort challenge
loyslane Aug 2, 2017
779b9a2
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 2, 2017
3fdbf6d
completed rotateImage challenge
loyslane Aug 3, 2017
d4f232f
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 3, 2017
e60fd48
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 4, 2017
7ad9b92
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 7, 2017
ee58768
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 8, 2017
822db4d
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 9, 2017
4fa8a0a
completed selectionSort.js
loyslane Aug 9, 2017
23bf507
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 10, 2017
97b24ff
completed rotatedArray.js
loyslane Aug 10, 2017
d625b36
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 11, 2017
d09296d
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 14, 2017
89b5974
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 15, 2017
d5e4176
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 16, 2017
e9f84f4
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 17, 2017
8eb8a01
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 18, 2017
acd1914
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 21, 2017
cca2f48
completed commonCharacters.js
loyslane Aug 21, 2017
8082b21
updated commonCharacters to ignore whitespace
loyslane Aug 21, 2017
3d95706
updated commonCharacters to return a string
loyslane Aug 21, 2017
e74b7f3
changed code so that str2 was added to the set without a for loop (di…
loyslane Aug 21, 2017
c79e1dd
completed fizzBuzz
loyslane Aug 21, 2017
0d41231
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 22, 2017
e7f6cd0
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 23, 2017
073ac2d
completed longestRun challenge
loyslane Aug 23, 2017
b4ab974
took out strArr since it was unneccessary
loyslane Aug 23, 2017
e3aba12
Merge branch 'master' of https://github.com/loyslane/CS1-Code-Challen…
loyslane Aug 24, 2017
f83d462
completed vowelCount Challenge
loyslane Aug 24, 2017
fe9d55f
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
loyslane Aug 25, 2017
a9c816c
completed meanMedianMode challenge
loyslane Aug 26, 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
28 changes: 27 additions & 1 deletion allAnagrams/allAnagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,30 @@
* example usage:
* const anagrams = allAnagrams('abc');
* console.log(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ]
*/
*/

const allAnagrams = (str) => {
const combos = [];
combos.push(str);
const strArr = Array.from(str);
let length = str.length;
if (length < 2) {
return str;
} else if (length === 2) {
strArr[0] = strArr[1];
strArr[1] = str[0];
combos.push(strArr.join(''));
return combos;
} else {
for (i = str.length - 1; i >= 1; i--) {
console.log(strArr);
const tempLetter = strArr[i];
console.log('tempLetter is ' + tempLetter + ' at i: ' + i);
strArr[i] = strArr[i - 1];
strArr[i - 1] = tempLetter;
console.log('new arr: ' + strArr);
combos.push(strArr.join(''));
}
}
return combos;
};
75 changes: 75 additions & 0 deletions array/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,78 @@
* 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.head = null;
this.tail = null;
this.length = 0;
}
push(element) {
const newNode = {
index: 0,
value: element,
next: null,
previous: null,
};
if (this.length === 0) {
this.head = newNode;
this.tail = newNode;
newNode.index = this.length;
this.length++;
} else if (this.length === 1) {
this.head.next = newNode;
newNode.previous = this.head;
this.tail = newNode;
newNode.index = this.length;
this.length++;
} else {
this.tail.next = newNode;
newNode.previous = this.tail;
this.tail = newNode;
newNode.index = this.length;
this.length++;
}
}
pop() {
this.tail = this.tail.previous;
}
get(index) {
let currentNode = this.head;
while (currentNode.value) {
if (currentNode.index === index) {
return currentNode.value;
}
currentNode = currentNode.next;
}
}
delete(index) {
let currentNode = this.head;
let nodePrevious;
let nodeNext;
while (currentNode.value) {
if (currentNode.index === index - 1) {
nodePrevious = currentNode;
currentNode = currentNode.next;
currentNode = currentNode.next;
while (currentNode.next) {
currentNode.previous = nodePrevious;
nodePrevious = currentNode;
currentNode.index -= 1;
currentNode = currentNode.next;
}
currentNode.previous = nodePrevious;
currentNode.index -= 1;
currentNode = currentNode.previous;
while (currentNode.index !== index) {
currentNode = currentNode.previous;
}
nodeNext = currentNode
currentNode = currentNode.previous;
currentNode.next = nodeNext;
return;
}
currentNode = currentNode.next;
}
}
}
16 changes: 15 additions & 1 deletion 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 - 1;
let mid = Math.floor(max/2);
const search = () => {
if (target === nums[mid]) {
return mid;
} else if (target > nums[mid]) {
min = mid + 1;
} else if (target < nums[mid]) {
max = mid - 1;
}
mid = min + Math.floor((max - min) / 2);
return search();
}
return search();
};
7 changes: 7 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
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. Fill up the five-quart jug and pour it into the three-quart jug, leaving two quarts left in the five-quart jug.
2. Pour out the three-quart jug.
3. Pour the two quarts from the five-quart jug into the three-quart jug, leaving two quarts in the three-quart jug and the five-quart jug empty.
4. Fill the the five-quart jug again.
5. Pour the five-quart jug into the three-quart jug until the three-quart jug is filled.
6. You now have four quarts of water in the five-quart jug.
19 changes: 19 additions & 0 deletions bubbleSort/bubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,23 @@

const bubbleSort = (arr) => {
//code here
const sortArr = () => {
for (i = 0; i < arr.length;) {
if (i < arr.length - 1) {
if (arr[i] < arr [i + 1]) {
i++;
}
if (arr[i] > arr[i + 1]) {
const x = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = x;
sortArr();
}
}
}
}
sortArr();
return arr;
};

// I know the time complexity is really high, but to be honest, I had a hard time getting it to actually work so I don't think I can figure out how to reduce the time complexity.
46 changes: 46 additions & 0 deletions callbackPractice/callbackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,97 @@

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

const firstItem = (arr, 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 = (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 = (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) => {
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) => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === item) {
return cb(true);
}
}
return cb(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 = (arr, cb) => {
const duplicateCheck = {};
const duplicatesRemoved = [];
for (let i = 0; i < arr.length; i++) {
if (!duplicateCheck[arr[i]]) {
duplicateCheck[arr[i]] = 1;
duplicatesRemoved.push(arr[i]);
}
}
cb(duplicatesRemoved);
}

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

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

const commonCharacters = (str1, str2) => {
let tempSet = new Set(str2);
let ansStr = '';
for (let i = 0; i < str1.length; i++) {
if (tempSet.has(str1[i]) && str1[i] !== ' ') {
ansStr += str1[i];
}
}
return ansStr;
};
Loading