Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a84878d
updated longestString.js
smith713 Jul 10, 2017
9343e00
updated longestString.js
smith713 Jul 10, 2017
221a220
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 11, 2017
fe6c58f
updated isUnique.js
smith713 Jul 11, 2017
f470a94
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 12, 2017
264d791
completed reverseCase.js
smith713 Jul 12, 2017
c8eefcb
Merge branch 'master' into master
smith713 Jul 13, 2017
f981c86
resolved merge coflicts
smith713 Jul 13, 2017
8ff940b
completed exercise
smith713 Jul 14, 2017
5ec50a2
completed exercises
smith713 Jul 14, 2017
d8658f4
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 14, 2017
d2515ab
completed evenOccurences.js
smith713 Jul 17, 2017
00dd615
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 17, 2017
a610665
completed callbackPractice.js
smith713 Jul 17, 2017
38059ba
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 18, 2017
bab7f40
completed forLoopTimeout.js
smith713 Jul 18, 2017
85c6fc7
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 19, 2017
b84dbe4
completed binarySearch.js
smith713 Jul 20, 2017
e1c3b3c
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 21, 2017
544da4e
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 24, 2017
e57c4bb
updated array.js
smith713 Jul 24, 2017
d11a127
added waterJugs.md
smith713 Jul 24, 2017
c158ab1
completed exercise
smith713 Jul 25, 2017
ccb7090
completed array.js
smith713 Jul 25, 2017
730356d
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 25, 2017
ee17742
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 26, 2017
ddb9ffd
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 28, 2017
58b04b0
uploaded operators.js
smith713 Jul 28, 2017
1e07b6e
uploaded constructors.js
smith713 Jul 28, 2017
864070b
completed queueStack.js
smith713 Jul 28, 2017
f9907ea
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 28, 2017
7377ee7
uploaded bubblesort.js
smith713 Jul 31, 2017
e27eeac
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Jul 31, 2017
184f9b8
completes allAnagrams
smith713 Aug 1, 2017
2520dd6
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 1, 2017
ebd6fee
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 2, 2017
47fc02b
uploaded insertionSort.js
smith713 Aug 2, 2017
f9e243b
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 3, 2017
bf621d9
completed rotateImage.js
smith713 Aug 4, 2017
1c830f1
completed logicGates.js
smith713 Aug 4, 2017
a54a2e9
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 4, 2017
7ea024c
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 7, 2017
3f75aa4
completed rockPaperScissors.js
smith713 Aug 8, 2017
2b8afff
uploaded parallel.js
smith713 Aug 8, 2017
436a587
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 8, 2017
a367cef
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 10, 2017
30bf5e5
completed quickSort
smith713 Aug 10, 2017
2f72fdb
completed selectionSort.js
smith713 Aug 10, 2017
ee654b6
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 14, 2017
f184aa9
completed rotatedArray.js
smith713 Aug 14, 2017
0867131
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 14, 2017
f79f817
completed linkedListCycle.js
smith713 Aug 14, 2017
58ed42f
completed blueSquares.js
smith713 Aug 15, 2017
95974b9
Merge branch 'master' of https://github.com/smith713/CS1-Code-Challen…
smith713 Aug 16, 2017
42a1b59
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 17, 2017
6a5a138
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 22, 2017
3c63d43
Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges
smith713 Aug 22, 2017
3adb878
updated files
smith713 Aug 22, 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' ]
*/
*/

let allAnagrams = (word, anagram = '', anagrams = []) => {
if(!word) {
anagrams.push(anagram);
return;
}
for (let i = 0; i < word.length; i++) {
anagram += word[i];
allAnagrams(word.slice(0, i) + word.slice(i + 1), anagram, anagrams);
anagram = anagram.slice(0, anagram.length - 1);
}
return [...new Set(anagrams)];
};


console.log(allAnagrams('abc')); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ]
console.log(allAnagrams('ab')); // [ 'ab', 'ba' ]
console.log(allAnagrams('1234')); // [ '1234','1243','1324', '1342', '1423', '1432', '2134', '2143', '2314', '2341',
//'2413', '2431', '3124', '3142', '3214', '3241', '3412', '3421', '4123', '4132', '4213', '4231', '4312', '4321' ]

// input! - factorial
33 changes: 33 additions & 0 deletions array/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,36 @@
* 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.storage = {};
this.count = 0;
}
push(value) {
this.storage[this.count] = value;
this.count++;
}

pop() {
this.count--;
delete this.storage[this.count];
return this.storage[this.count];
}

get(index) {
return this.storage[index];
}

delete(index) {
if(index < 0 || index >= this.count)
return undefined;
const deletedValue = this.storage[index];
for(let i = index; i < this.count; i++) {
this.storage[i] = this.storage[i + 1];
}
this.storage--;
return deletedValue;
}
}

19 changes: 18 additions & 1 deletion binarySearch/binarySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
* * console.log(index); // 1
**/

const binarySearch = (nums, target) => {

const binarySearch = (nums, target) => {
let start = 0;
let end = nums.length - 1;

while(start <= end) {
let mid = (Math.floor((start + end) / 2));
if(nums[mid] === target) {
return mid;
} else if(target < nums[mid]) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return -1;
};

const index = binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2);
console.log(index);
32 changes: 32 additions & 0 deletions blueSquares/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Lambda University | blueSquares</title>
</head>
<body>
<div class="square">
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
</div>
<div class="square">
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
</div>
<div class="square">
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
<div class="squares"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions blueSquares/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

$(document).ready(function() {
$('.squares').click(function() {
$(this).toggleClass('clicked');
});
});
18 changes: 18 additions & 0 deletions blueSquares/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.square {
display: -webkit-flex;
display: flex;
width: 100%;
-webkit-justify-content: center;
justify-content: center;
}

.squares {
background-color: #FF0000;
width: 200px;
height: 200px;
margin: 5px;
}

.clicked {
background: #0000FF;
}
11 changes: 11 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
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.

5 Quart | 3 Quart
------------------
0 | 3
3 | 0
3 | 3
5 | 1
0 | 1
1 | 0
1 | 3
4 | 0
22 changes: 21 additions & 1 deletion bubbleSort/bubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,25 @@
*/

const bubbleSort = (arr) => {
//code here
if(arguments.length === 0 || !Array.isArray(arr)) {
return 'Invalid input array';
}
for(let i = (arr.length - 1); i >= 0; i--) {
for(let j = (arr.length - 1); j > 0; j--) {
if (arr[j] < arr[j - 1]) {
let temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
return arr;
};

console.log(bubbleSort([1, 2, 3])); // [1, 2, 3]
console.log(bubbleSort([2, 1, 3])); // [1, 2, 3]
console.log(bubbleSort([])); // Invalid input array
console.log(bubbleSort({foo: 123})); // Invalid input array
console.log(bubbleSort('foobar')); // Invalid input array
console.log(bubbleSort(undefined)); // Invalid input array
console.log(bubbleSort([161, 48, 56, 545, 2, 77])); // [2, 48, 56, 77, 161, 545]
44 changes: 44 additions & 0 deletions callbackPractice/callbackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,95 @@

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 = (x, y, cb) => {
let sum = x + y;
cb(sum);
};

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) => {
let product = x * y;
cb(product);
};

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) => {
if (arr.indexOf(item) !== -1) {
return cb(item);
}
return cb(!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) => {
var temp = [];
for (i = 0; i < arr.length; i++) {
if (temp.indexOf(arr[i]) === -1) {
temp.push(arr[i]);
}
}
cb(temp);
};

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 (var i = 0; i < arr.length; i++){
cb(arr[i], i);
}
};

forEach(foods, (value, index) => {
console.log(`${value} is at index ${index}.`);
});
Loading