├── .gitignore ├── _config.yml ├── .gitattributes ├── 14-fibonacci.js ├── 05-fizz-buzz.js ├── 10-reverse-array-in-place.js ├── 12-two-sum.js ├── 08-caesar-cipher.js ├── 17-bubble-sort.js ├── 02-recursion.js ├── 09-reverse-words.js ├── 13-binary-search.js ├── 16-sieve-of-eratosthenes.js ├── 15-memoized-fibonacci.js ├── 07-palindrome.js ├── 19-max-stock-profit.js ├── 06-harmless-ransom-note.js ├── 18-merge-sort.js ├── 11-mean-median-mode.js ├── LICENSE ├── bigO.js ├── 04-hash-table.js ├── 03-binary-search-tree.js ├── 01-linked-list.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /14-fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(num) { 2 | if(num===1 || num===2) return 1; 3 | return fibonacci(num-1) + fibonacci(num-2); 4 | } 5 | 6 | console.log(fibonacci(20)); -------------------------------------------------------------------------------- /05-fizz-buzz.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N) 2 | 3 | function fizzBuzz(num) { 4 | for (var i=1;i<=num; i++){ 5 | if(i % 3 == 0 && i % 5 == 0) console.log('FuzzBuzz'); 6 | else if(i % 3 == 0) console.log('Fizz'); 7 | else if(i % 5 == 0) console.log('Buzz'); 8 | else console.log(i); 9 | } 10 | } 11 | 12 | fizzBuzz(22); -------------------------------------------------------------------------------- /10-reverse-array-in-place.js: -------------------------------------------------------------------------------- 1 | function reverseArrayInPlace(arr) { 2 | for (var i = 0; i < arr.length/2; i++) { 3 | var tempElm = arr[i]; 4 | arr[i] = arr[arr.length-i-1]; 5 | arr[arr.length-i-1] = tempElm; 6 | } 7 | return arr; 8 | } 9 | 10 | console.log(reverseArrayInPlace(['andy', 'is', 'amazing', 'and', 'smart'])); -------------------------------------------------------------------------------- /12-two-sum.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N) 2 | 3 | function twoSum(numArray, sum) { 4 | var pairs = []; 5 | var hashTable = []; 6 | 7 | for (var i = 0; i < numArray.length; i++) { 8 | var currNum = numArray[i]; 9 | var counterPart = sum-currNum; 10 | if(hashTable.indexOf(counterPart)>-1) pairs.push([currNum, counterPart]); 11 | else hashTable.push(currNum); 12 | } 13 | 14 | return pairs; 15 | } 16 | 17 | console.log(twoSum([1,6,4,5,3,3], 7)); -------------------------------------------------------------------------------- /08-caesar-cipher.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N) 2 | 3 | function caesarCipher(str, num) { 4 | var alphArr = 'abcdefghijklmnopqrstuvwxyz'.split(''); 5 | var strArr = str.toLowerCase().split(''); 6 | var resulrArr = strArr.map(s=>{ 7 | if (s === ' ') return ' '; 8 | var i = (alphArr.indexOf(s) + num) % alphArr.length; 9 | return alphArr[i]; 10 | }) 11 | return resulrArr.join(''); 12 | } 13 | 14 | console.log(caesarCipher("Zoo keeper", 2)); // bqq mggrgt -------------------------------------------------------------------------------- /17-bubble-sort.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (n^2) //-> actually takes (array.length - 1) passes; 2 | 3 | function bubbleSort(array) { 4 | for (var i = array.length; i > 0; i--) { 5 | for (var j = 0; j < i; j++) { 6 | if (array[j] > array[j + 1]) { 7 | var temp = array[j]; 8 | array[j] = array[j + 1]; 9 | array[j + 1] = temp; 10 | } 11 | } 12 | } 13 | return array; 14 | } 15 | 16 | console.log(bubbleSort([5, 3, 8, 2, 1, 4])); -------------------------------------------------------------------------------- /02-recursion.js: -------------------------------------------------------------------------------- 1 | // 02 Recursion 2 | // The recursion function will call itself until the basecase is satisfied 3 | 4 | // function func() { 5 | // if(/*base case*/) { 6 | // return /*something*/; 7 | // }else{ 8 | // /*resursive case*/ 9 | // return func(); 10 | // } 11 | // }; 12 | 13 | // Factorial function 14 | function factorial(num){ 15 | if (num === 1) { 16 | return num; 17 | }else{ 18 | return num * factorial(num-1); 19 | } 20 | } 21 | 22 | console.log(factorial(5)); -------------------------------------------------------------------------------- /09-reverse-words.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N^2) <- not sure 2 | 3 | function reverseWords(string) { 4 | var stringArr = string.split(' '); 5 | 6 | var result = stringArr.map(s => { 7 | var sArr = s.split(''); 8 | var nArr = []; 9 | sArr.forEach(s=>{ 10 | nArr.unshift(s); 11 | }) 12 | return nArr.join(''); 13 | // return s.split('').reverse().join(''); 14 | }); 15 | 16 | return result.join(' '); 17 | } 18 | 19 | console.log(reverseWords('this is a string of words')) //siht si a gnirts fo sdrow -------------------------------------------------------------------------------- /13-binary-search.js: -------------------------------------------------------------------------------- 1 | function binarySearch(arr, key) { 2 | arr.sort((a,b)=>a-b); 3 | var min = arr[0]; 4 | var max = arr[arr.length - 1]; 5 | var mid = (min + max) / 2; 6 | console.log(arr); 7 | if (min === key || max === key || mid === key) return true; 8 | else if (key < mid) { 9 | return binarySearch(arr.slice(0, (arr.length / 2)), key); 10 | } else if (key > mid) { 11 | return binarySearch(arr.slice(Math.floor((arr.length / 2))),key); 12 | } 13 | } 14 | 15 | console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 2)); -------------------------------------------------------------------------------- /16-sieve-of-eratosthenes.js: -------------------------------------------------------------------------------- 1 | function sieveOfEratosthenes(n) { 2 | var primesStatus = []; 3 | for (var i=0; i<=n ; i++) { 4 | primesStatus[i] = true; 5 | } 6 | primesStatus[0] = false; 7 | primesStatus[1] = false; 8 | 9 | for (var i = 2; i<=Math.sqrt(n); i++) { 10 | for(var j = 2; j * i <= n; j++) { 11 | primesStatus[i*j] = false; 12 | } 13 | } 14 | 15 | var result = []; 16 | primesStatus.forEach((s, i)=>{ 17 | if(s) result.push(i); 18 | }) 19 | return result; 20 | } 21 | 22 | console.log(sieveOfEratosthenes(300)); -------------------------------------------------------------------------------- /15-memoized-fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(num, dict = {}) { 2 | if(dict[num]) return dict[num]; 3 | if(num===1 || num===2) return 1; 4 | return dict[num] = fibonacci(num-1, dict) + fibonacci(num-2, dict); 5 | } 6 | 7 | function fibMemo(index, cache) { 8 | cache = cache || []; 9 | if (cache[index]) return cache[index]; 10 | else { 11 | if (index < 3) return 1; 12 | else { 13 | cache[index] = fibMemo(index - 1, cache) + fibMemo(index - 2, cache); 14 | } 15 | } 16 | return cache[index]; 17 | } 18 | 19 | console.log(fibonacci(100)); 20 | console.log(fibMemo(100)); -------------------------------------------------------------------------------- /07-palindrome.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N) 2 | 3 | function isPalindrame(string) { 4 | string = string.toLowerCase(); 5 | var charactersArr = string.split(''); 6 | var validCharasters = 'abcdefghijklmnopqrstuvwxyz'.split(''); 7 | 8 | var letterArr = []; 9 | charactersArr.forEach(c => { 10 | if (validCharasters.indexOf(c) > -1) letterArr.push(c); 11 | }); 12 | return (letterArr.join('') === letterArr.reverse().join('')) 13 | } 14 | 15 | console.log(isPalindrame("Madam I'm Adam")); // true 16 | console.log(isPalindrame("Race Car")); // true 17 | console.log(isPalindrame("A Race Car")); // false -------------------------------------------------------------------------------- /19-max-stock-profit.js: -------------------------------------------------------------------------------- 1 | function maxStockProfit(pricesArr) { 2 | var profit = -1; 3 | var buyPrice = 0; 4 | var sellPrice = 0; 5 | 6 | var changeBuyPrice = true; 7 | 8 | for (var i = 0; i < pricesArr.length; i++) { 9 | if(changeBuyPrice) buyPrice = pricesArr[i]; 10 | sellPrice = pricesArr[i + 1]; 11 | 12 | if(sellPrice < buyPrice) { 13 | changeBuyPrice = false; 14 | } 15 | 16 | else { 17 | var tempProfit = sellPrice - buyPrice; 18 | if(tempProfit > profit) profit = tempProfit; 19 | changeBuyPrice = true; 20 | } 21 | } 22 | 23 | return profit; 24 | } 25 | 26 | console.log(maxStockProfit([10, 18, 4, 5, 9, 6, 16, 12])); -------------------------------------------------------------------------------- /06-harmless-ransom-note.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (n) + O (m) /-> O (n+m) or O(n) 2 | // n = noteText.length; 3 | // m = magazinText.length; 4 | 5 | function harmlessRansomNote(noteText, magazinText) { 6 | var noteArr = noteText.split(" "); 7 | var magazinArr = magazinText.split(" "); 8 | var magazinObj = {}; 9 | var result = true; 10 | 11 | magazinArr.forEach(w => magazinObj[w] ? magazinObj[w]++ : magazinObj[w] = 1); 12 | 13 | noteArr.forEach(w => { 14 | if(magazinObj[w]) { 15 | magazinObj[w]-- 16 | if(magazinObj[w]<0)result=false; 17 | } 18 | else result = false; 19 | }) 20 | console.log(result); 21 | return result; 22 | } 23 | 24 | harmlessRansomNote('Andy is amazing amazing', 'This is the amazing Andy Andy'); // false -------------------------------------------------------------------------------- /18-merge-sort.js: -------------------------------------------------------------------------------- 1 | function mergeSort(arr) { 2 | if (arr.length < 2) return arr; 3 | var middleIndex = Math.floor(arr.length / 2); 4 | var firstHalf = arr.slice(0, middleIndex); 5 | var secondHalf = arr.slice(middleIndex); 6 | return merge(mergeSort(firstHalf), mergeSort(secondHalf)); 7 | } 8 | 9 | function merge(array1, array2) { 10 | var result = []; 11 | while(array1.length && array2.length) { 12 | var minElm; 13 | if(array1[0] < array2[0]) minElm = array1.shift(); 14 | else minElm = array2.shift(); 15 | result.push(minElm); 16 | } 17 | if(array1.length) result = result.concat(array1); 18 | else if(array2.length) result = result.concat(array2); 19 | return result; 20 | } 21 | 22 | // console.log(mergeSort([3,5,8,20], [1,2,12,17])); 23 | console.log(mergeSort([11, 7, 4, 1, 15, 12, 3])); -------------------------------------------------------------------------------- /11-mean-median-mode.js: -------------------------------------------------------------------------------- 1 | function getMean(arr) { 2 | return arr.reduce((sum, curr) => sum += curr, 0) / arr.length; 3 | } 4 | 5 | function getMedian(arr) { 6 | arr.sort((a, b) => a > b); 7 | if ((arr.length % 2) === 0) { 8 | return (arr[arr.length / 2] + arr[arr.length / 2 - 1]) / 2 9 | } else { 10 | return arr[Math.floor(arr.length / 2)]; 11 | } 12 | } 13 | 14 | function getMode(arr) { 15 | var obj = {}; 16 | var modes = []; 17 | var maxCount = 0; 18 | arr.forEach(e => { 19 | obj[e] ? obj[e]++ : obj[e] = 1; 20 | if (obj[e] > maxCount) { 21 | modes = [e]; 22 | maxCount = obj[e]; 23 | } 24 | if (obj[e] === maxCount && modes.indexOf(e) == -1) { 25 | modes.push(e); 26 | } 27 | }); 28 | if (modes.length === Object.keys(obj).length) modes = []; 29 | return modes; 30 | } 31 | 32 | function meanMedianMode(arr) { 33 | return { 34 | mean: getMean(arr), 35 | median: getMedian(arr), 36 | mode: getMode(arr) 37 | } 38 | } 39 | 40 | 41 | console.log(meanMedianMode([1, 1, 3, 3, 4, 4, 5, 5, 6])) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) Andy Chen (amazingandyyy.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /bigO.js: -------------------------------------------------------------------------------- 1 | // Constant runtime - Big O Notation: "O (1)" 2 | function log(array) { 3 | console.log(array[0]); 4 | console.log(array[1]); 5 | } 6 | 7 | log([1, 2, 3, 4]); 8 | log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 9 | 10 | 11 | // Linear runtime - Big O Notation: "O (n)" 12 | function logAll(array) { 13 | for (var i = 0; i < array.length; i++) { 14 | console.log(array[i]); 15 | } 16 | } 17 | 18 | logAll([1, 2, 3, 4, 5]); 19 | logAll([1, 2, 3, 4, 5, 6]); 20 | logAll([1, 2, 3, 4, 5, 6, 7]); 21 | 22 | 23 | // Exponential runtime - Big O Notation: "O (n^2)" 24 | function addAndLog(array) { 25 | for (var i = 0; i < array.length; i++) { 26 | for (var j = 0; j < array.length; j++) { 27 | console.log(array[i] + array[j]); 28 | } 29 | } 30 | } 31 | 32 | addAndLog(['A', 'B', 'C']); // 9 pairs logged out 33 | addAndLog(['A', 'B', 'C', 'D']); // 16 pairs logged out 34 | addAndLog(['A', 'B', 'C', 'D', 'E']); // 25 pairs logged out 35 | 36 | 37 | // Logarithmic runtime - Big O Notation: O (log n) 38 | function binarySearch(array, key) { 39 | var low = 0; 40 | var high = array.length - 1; 41 | var mid; 42 | var element; 43 | 44 | while (low <= high) { 45 | mid = Math.floor((low + high) / 2, 10); 46 | element = array[mid]; 47 | if (element < key) { 48 | low = mid + 1; 49 | } else if (element > key) { 50 | high = mid - 1; 51 | } else { 52 | return mid; 53 | } 54 | } 55 | return -1; 56 | } -------------------------------------------------------------------------------- /04-hash-table.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (1) 2 | 3 | class HashTable { 4 | constructor(size) { 5 | this.bucket = Array(size); 6 | this.numBucket = this.bucket.length; 7 | } 8 | hash(key) { 9 | var total = key.split("").reduce((curr, next) => curr + next.charCodeAt(0), 0); 10 | return total % this.numBucket; 11 | } 12 | insert(key, value) { 13 | var index = this.hash(key); 14 | if (!this.bucket[index]) 15 | this.bucket[index] = new HashNode(key, value); 16 | else if (this.bucket[index].key === key) { 17 | // update value if it's already exist 18 | this.bucket[index].value = value; 19 | } 20 | else { 21 | var currentNode = this.bucket[index]; 22 | while (currentNode.next) { 23 | if (currentNode.next.key === key) { 24 | // in order to check the last element in this while loop 25 | currentNode.next.value = value; 26 | return; 27 | } 28 | currentNode = currentNode.next; 29 | } 30 | currentNode.next = new HashNode(key, value); 31 | } 32 | } 33 | get(key) { 34 | var index = this.hash(key); 35 | if (!this.bucket[index]) return null; 36 | if (this.bucket[key] === key) return this.bucket[key]; 37 | else { 38 | var currentNode = this.bucket[index]; 39 | while (currentNode) { 40 | if (currentNode.key === key) return currentNode; 41 | currentNode = currentNode.next; 42 | } 43 | return null; 44 | } 45 | } 46 | retriveAll() { 47 | var result = []; 48 | for (var i=0 ; i < this.numBucket; i++){ 49 | var currentNode = this.bucket[i]; 50 | while(currentNode) { 51 | result.push(currentNode); 52 | currentNode = currentNode.next; 53 | } 54 | } 55 | return result; 56 | } 57 | } 58 | 59 | function HashNode(key, value, next) { 60 | this.key = key; 61 | this.value = value; 62 | this.next = next || null; 63 | } 64 | 65 | var myHT = new HashTable(30); 66 | 67 | myHT.insert('Andy', 'andy@mail.com'); 68 | myHT.insert('Nady', 'nady@mail.com'); 69 | myHT.insert('Bob', 'bob@mail.com'); 70 | 71 | console.log('old', myHT); 72 | 73 | myHT.insert('Andy', 'andy-new@mail.com'); 74 | // console.log('new', myHT); 75 | 76 | // console.log(myHT.get("Nayd")); // null 77 | // console.log(myHT.get("Andy")); // 'andy-new@mail.com' 78 | console.log('retriveAll', myHT.retriveAll()); -------------------------------------------------------------------------------- /03-binary-search-tree.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (log(n)) 2 | 3 | class BST { 4 | constructor(value) { 5 | this.value = value; 6 | this.left = null; 7 | this.right = null; 8 | } 9 | insert(value) { 10 | if (value <= this.value) { 11 | if (!this.left) 12 | this.left = new BST(value); 13 | else 14 | this.left.insert(value); 15 | } 16 | else if (value > this.value) { 17 | if (!this.right) 18 | this.right = new BST(value); 19 | else 20 | this.right.insert(value); 21 | } 22 | } 23 | contains(value) { 24 | if (value === this.value) 25 | return true; 26 | else if (value <= this.value) { 27 | if (!this.left) 28 | return false; 29 | else 30 | return this.left.contains(value); 31 | } 32 | else if (value > this.value) { 33 | if (!this.right) 34 | return false; 35 | else 36 | return this.right.contains(value); 37 | } 38 | } 39 | depthFirstTraversal(iteratorFunc, order) { 40 | if (order === 'pre-order') 41 | iteratorFunc(this.value); // print the parent first 42 | if (this.left) 43 | this.left.dethFirstTraversal(iteratorFunc, order); 44 | if (order === 'in-order') 45 | iteratorFunc(this.value); // print from smallest to biggest 46 | if (this.right) 47 | this.right.dethFirstTraversal(iteratorFunc, order); 48 | if (order === 'post-order') 49 | iteratorFunc(this.value); // print children first 50 | } 51 | breadthFirstTraversal(iteratorFunc) { 52 | // level by level 53 | var queue = [this]; 54 | while (queue.length) { 55 | var treeNode = queue.shift(); 56 | iteratorFunc(treeNode); 57 | if (treeNode.left) 58 | queue.push(treeNode.left); 59 | if (treeNode.right) 60 | queue.push(treeNode.right); 61 | } 62 | } 63 | getMinVal() { 64 | if (this.left) 65 | return this.left.getMinVal(); 66 | else 67 | return this.value; 68 | } 69 | getMaxVal() { 70 | if (this.right) 71 | return this.right.getMaxVal(); 72 | else 73 | return this.value; 74 | } 75 | } 76 | 77 | 78 | var bst = new BST(50); 79 | bst.insert(30); 80 | bst.insert(70); 81 | bst.insert(100); 82 | bst.insert(60); 83 | bst.insert(59); 84 | bst.insert(20); 85 | bst.insert(45); 86 | bst.insert(35); 87 | bst.insert(85); 88 | bst.insert(105); 89 | bst.insert(10); 90 | 91 | // console.log(bst.contains(20)); 92 | // bst.depthFirstTraversal(log, 'post-order'); 93 | console.log(bst.getMaxVal()); 94 | 95 | function log(val) { 96 | console.log(val); 97 | } -------------------------------------------------------------------------------- /01-linked-list.js: -------------------------------------------------------------------------------- 1 | // Big O Notation: O (N) 2 | 3 | class LinkedList { 4 | constructor() { 5 | this.head = null; 6 | this.tail = null; 7 | } 8 | addToHead(value) { 9 | // O(1) 10 | // add a new head to extend the old head 11 | var newNode = new Node(value, this.head, null); 12 | if (this.head) 13 | this.head.prev = newNode; 14 | else 15 | this.tail = newNode; 16 | this.head = newNode; 17 | } 18 | addToTail(value) { 19 | // O(1) 20 | var newNode = new Node(value, null, this.tail); 21 | if (this.tail) 22 | this.tail.next = newNode; 23 | else 24 | this.head = newNode; 25 | this.tail = newNode; 26 | } 27 | removeTheHead() { 28 | // O(1) 29 | if (!this.head) 30 | return null; 31 | var val = this.head.value; 32 | this.head = this.head.next; 33 | if (this.head) 34 | this.head.prev = null; 35 | else 36 | this.tail = null; 37 | return val; 38 | } 39 | removeTheTail() { 40 | // O(1) 41 | if (!this.tail) 42 | return null; 43 | var val = this.tail.value; 44 | this.tail = this.tail.prev; 45 | if (this.tail) 46 | this.tail.next = null; 47 | else 48 | this.head = null; 49 | return val; 50 | } 51 | searchNodesWithValueOf(val) { 52 | // O(n) 53 | var result = []; 54 | var currentNode = this.head; 55 | while (currentNode) { 56 | if (currentNode.value == val) 57 | result.push(currentNode); 58 | currentNode = currentNode.next; 59 | } 60 | return result; 61 | } 62 | updatehNodesWithValueOf(val, newVal) { 63 | // O(n) 64 | var targetNodes = this.searchNodesWithValueOf(val); 65 | targetNodes.forEach((n) => { 66 | n.value = newVal; 67 | }); 68 | return targetNodes; 69 | } 70 | indexOf(index) { 71 | var currentNode = this.head; 72 | var count = 0; 73 | while (currentNode) { 74 | if (count == index) 75 | return currentNode; 76 | count++; 77 | currentNode = currentNode.next; 78 | } 79 | return currentNode; 80 | } 81 | } 82 | 83 | function Node(value, next, prev) { 84 | this.value = value; 85 | this.next = next; 86 | this.prev = prev; 87 | } 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | // Testing/// 97 | 98 | var ll = new LinkedList(); 99 | 100 | ll.addToHead(11); // 4 101 | ll.addToHead(22); // 3 102 | ll.addToHead(33); // 2 103 | ll.addToHead(12); // 1 104 | ll.addToHead(55); // 0 105 | 106 | console.log(ll.updatehNodesWithValueOf(11, 88)); 107 | // console.log(ll.searchNodesWithValueOf(11)); 108 | // console.log(ll.indexOf(2)) // return 33 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms in Javascript 2 | 3 | Write basic data structure and algorithms in javascript, my favorite language without a doubt. 4 | 5 | ## Why JS 6 | 7 | When it comes to the data structure, people first think about python or Java which I personally don’t think they are the choice. Javascript itself is a more beautiful, flexible and friendly language in the following reason: 8 | 9 | - Runs everywhere, thanks to node 10 | - Curly braces are the best, to have clear code blocks and scope 11 | - Event-driven makes projects written in JS more accessible and fun 12 | - Weak type makes more intuitive (well... I still love golang) 13 | - A better OOP class (over than python's underscores) 14 | - The best testing cycle 15 | 16 | ## Topics 17 | 18 | - 01 [Linked List](https://github.com/amazingandyyy/algorithms-in-js/blob/master/01-linked-list.js) 19 | - 02 [Recursion](https://github.com/amazingandyyy/algorithms-in-js/blob/master/02-recursion.js) 20 | - 03 [Binary Search Tree](https://github.com/amazingandyyy/algorithms-in-js/blob/master/03-binary-search-tree.js) 21 | - 04 [Hash Table](https://github.com/amazingandyyy/algorithms-in-js/blob/master/04-hash-table.js) 22 | - 05 [Fizz Buzz](https://github.com/amazingandyyy/algorithms-in-js/blob/master/05-fizz-buzz.js) 23 | - 06 [Harmless Ransom Note](https://github.com/amazingandyyy/algorithms-in-js/blob/master/06-harmless-ransom-note.js) 24 | - 07 [Palindrome](https://github.com/amazingandyyy/algorithms-in-js/blob/master/07-palindrome.js) 25 | - 08 [Caesar Cipher](https://github.com/amazingandyyy/algorithms-in-js/blob/master/08-caesar-cipher.js) 26 | - 09 [Reverse Words](https://github.com/amazingandyyy/algorithms-in-js/blob/master/09-reverse-words.js) 27 | - 10 [Reverse Array In Place](https://github.com/amazingandyyy/algorithms-in-js/blob/master/10-reverse-array-in-place.js) 28 | - 11 [Mean Median Mode](https://github.com/amazingandyyy/algorithms-in-js/blob/master/11-mean-median-mode.js) 29 | - 12 [Two Sum](https://github.com/amazingandyyy/algorithms-in-js/blob/master/12-two-sum.js) 30 | - 13 [Binary Search](https://github.com/amazingandyyy/algorithms-in-js/blob/master/13-binary-search.js) 31 | - 14 [Fibonacci](https://github.com/amazingandyyy/algorithms-in-js/blob/master/14-fibonacci.js) 32 | - 15 [Memoized Fibonacci](https://github.com/amazingandyyy/algorithms-in-js/blob/master/15-memoized-fibonacci.js) 33 | - 16 [Sieve Of Eratosthenes](https://github.com/amazingandyyy/algorithms-in-js/blob/master/16-sieve-of-eratosthenes.js) 34 | - 17 [Bubble Sort](https://github.com/amazingandyyy/algorithms-in-js/blob/master/17-bubble-sort.js) 35 | - 18 [Merge Sort](https://github.com/amazingandyyy/algorithms-in-js/blob/master/18-merge-sort.js) 36 | - 19 [Max Stock Profit](https://github.com/amazingandyyy/algorithms-in-js/blob/master/19-max-stock-profit.js) 37 | 38 | 39 | ## Resources 40 | 41 | - [x] **Learning Algorithms in Javascript from Scratch** by Eric Traub on [udemy](https://www.udemy.com/learning-algorithms-in-javascript-from-scratch) 42 | - [x] **Learning Data Structures in Javascript from Scratch** by Eric Traub on [udemy](https://www.udemy.com/learning-data-structures-in-javascript-from-scratch/) 43 | - [ ] **The Coding Interview Bootcamp: Algorithms + Data Structures** by Stephen Grider on [udemy](https://www.udemy.com/coding-interview-bootcamp-algorithms-and-data-structure/learn/v4/) 44 | - [ ] **Welcome to Data Structure and Algorithms Analysis - Job Interview** by Hussein Al Rubaye on [udemy](https://www.udemy.com/data-structure-and-algorithms-analysis/learn/v4/overview) 45 | - [ ] **C Language + Algorithms + Data Structures = Power** by Nidhal Abidi on [udemy](https://www.udemy.com/clang-algo-ds/learn/v4/overview) 46 | - [ ] **Easy to Advanced Data Structures** by William Fiset on [udemy](https://www.udemy.com/introduction-to-data-structures/learn/v4/overview) 47 | - [x] **10 Common Data Structures Explained with Videos + Exercises** by Beau Carnes on [medium](https://medium.freecodecamp.org/10-common-data-structures-explained-with-videos-exercises-aaff6c06fb2b) 48 | 49 | ## Author 50 | 51 | Andy Chen ([amazingandyyy](https://github.com/amazingandyyy)) 52 | 53 | ## LICENSE 54 | 55 | [MIT](https://github.com/amazingandyyy/algorithms-in-js/blob/master/LICENSE) 56 | --------------------------------------------------------------------------------