├── Algorithm ├── fibonacci.js ├── fizzBuzz.js ├── reverseArrayInPlace.js ├── bubbleSort.js ├── memoizedFibonacci.js ├── reverseWords.js ├── isPalindrome.js ├── twoSum.js ├── binarySearch.js ├── sieveOfEratosthenes.js ├── maxStockProfit.js ├── mergeSort.js ├── caesarCipher.js ├── harmlessRansomNote.js └── meanMedianMode.js ├── DataStructures ├── constructor.js ├── recursion.js ├── prototypeObject.js ├── bigOnotation.js ├── linkedList.js ├── hashTable.js └── binarySearchTree.js └── README.md /Algorithm/fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(position) { 2 | if (position < 3) return 1; 3 | else return fibonacci(position - 1) + fibonacci(position - 2); 4 | } 5 | 6 | fibonacci(12); // 144 7 | -------------------------------------------------------------------------------- /DataStructures/constructor.js: -------------------------------------------------------------------------------- 1 | function User(firstName, lastName, age, gender) { 2 | this.firstName = firstName; 3 | this.lastName = lastName; 4 | this.age = age; 5 | this.gender; 6 | } 7 | 8 | let user1 = new User('Dhimas', 'Akbar', 18, 'male'); 9 | 10 | user1 -------------------------------------------------------------------------------- /DataStructures/recursion.js: -------------------------------------------------------------------------------- 1 | function factorial(num) { 2 | if (num === 1) { 3 | return num; 4 | } else { 5 | let hitung = num * factorial(num - 1); 6 | console.log(hitung); 7 | return num * factorial(num - 1); 8 | } 9 | } 10 | 11 | factorial(4); -------------------------------------------------------------------------------- /Algorithm/fizzBuzz.js: -------------------------------------------------------------------------------- 1 | function fizzBuzz(num) { 2 | for (let i = 1; i <= num; i++) { 3 | if (i % 15 === 0) console.log('FizzBuzz'); 4 | else if (i % 3 === 0) console.log('Fizz'); 5 | else if (i % 5 === 0) console.log('Buzz'); 6 | else console.log(i); 7 | } 8 | } 9 | 10 | fizzBuzz(30); -------------------------------------------------------------------------------- /Algorithm/reverseArrayInPlace.js: -------------------------------------------------------------------------------- 1 | function reverseArrayInPlace(arr) { 2 | for (let i = 0; i < arr.length / 2; i++) { 3 | let tempVar = arr[i]; 4 | arr[i] = arr[arr.length - 1 - i]; 5 | arr[arr.length - 1 - i] = tempVar; 6 | } 7 | 8 | return arr; 9 | } 10 | 11 | reverseArrayInPlace([1, 2, 3, 4, 5, 6, 7]); 12 | -------------------------------------------------------------------------------- /Algorithm/bubbleSort.js: -------------------------------------------------------------------------------- 1 | function bubbleSort(arr) { 2 | for (let i = arr.length; i > 0; i--) { 3 | for (let j = 0; j < i; j++) { 4 | if (arr[j] > arr[j + 1]) { 5 | let temp = arr[j]; 6 | arr[j] = arr[j + 1]; 7 | arr[j + 1] = temp; 8 | } 9 | } 10 | } 11 | 12 | return arr; 13 | } 14 | 15 | bubbleSort([5, 3, 8, 2, 1, 4]); // [ 1, 2, 3, 4, 5, 8 ] 16 | -------------------------------------------------------------------------------- /Algorithm/memoizedFibonacci.js: -------------------------------------------------------------------------------- 1 | function memoizedFibonacci(index, cache) { 2 | cache = cache || []; 3 | if (cache[index]) return cache[index]; 4 | else { 5 | if (index < 3) return 1; 6 | else { 7 | cache[index] = 8 | memoizedFibonacci(index - 1, cache) + 9 | memoizedFibonacci(index - 2, cache); 10 | } 11 | } 12 | 13 | return cache[index]; 14 | } 15 | 16 | memoizedFibonacci(1000); // 4.346655768693743e+208 17 | -------------------------------------------------------------------------------- /DataStructures/prototypeObject.js: -------------------------------------------------------------------------------- 1 | function User(firstName, lastName, age, gender) { 2 | this.firstName = firstName; 3 | this.lastName = lastName; 4 | this.age = age; 5 | this.gender; 6 | } 7 | 8 | let user1 = new User('Dhimas', 'Akbar', 18, 'male'); 9 | 10 | user1 11 | 12 | User.prototype.emailDomain = '@gmail.com'; 13 | 14 | User.prototype.getEmailAddress = function() { 15 | return this.firstName + this.lastName + this.emailDomain; 16 | } 17 | 18 | user1.getEmailAddress(); -------------------------------------------------------------------------------- /Algorithm/reverseWords.js: -------------------------------------------------------------------------------- 1 | function reverseWords(string) { 2 | let wordsArr = string.split(" "); 3 | let reversedWordsArr = []; 4 | 5 | wordsArr.forEach(word => { 6 | let reversedWord = ""; 7 | for (let i = word.length - 1; i >= 0; i--) { 8 | reversedWord += word[i]; 9 | } 10 | reversedWordsArr.push(reversedWord); 11 | }); 12 | 13 | return reversedWordsArr.join(" "); 14 | } 15 | 16 | reverseWords("this is a string of words"); // siht si a gnirts fo sdrow 17 | 18 | reverseWords("Dhimas Akbar"); // samihD rabkA 19 | -------------------------------------------------------------------------------- /Algorithm/isPalindrome.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(string) { 2 | string = string.toLowerCase(); 3 | let charactersArr = string.split(''); 4 | let validCharacters = 'abcdefghijklmnopqrstuvwxyz'.split(''); 5 | 6 | let lettersArr = []; 7 | charactersArr.forEach(char => { 8 | if (validCharacters.indexOf(char) > -1) lettersArr.push(char); 9 | }); 10 | 11 | if (lettersArr.join('') === lettersArr.reverse().join('')) return true; 12 | else return false; 13 | } 14 | 15 | console.log(isPalindrome("Madam I'm Adam")); -------------------------------------------------------------------------------- /Algorithm/twoSum.js: -------------------------------------------------------------------------------- 1 | function twoSum(numArray, sum) { 2 | let pairs = []; 3 | let hashtable = []; 4 | 5 | for (let i = 0; i < numArray.length; i++) { 6 | let currNum = numArray[i]; 7 | let counterpart = sum - currNum; 8 | if (hashtable.indexOf(counterpart) !== -1) { 9 | pairs.push([currNum, counterpart]); 10 | } 11 | hashtable.push(currNum); 12 | } 13 | 14 | return pairs; 15 | } 16 | 17 | twoSum([1, 6, 4, 5, 3, 3], 7); // [ [ 6, 1 ], [ 3, 4 ], [ 3, 4 ] ] 18 | 19 | twoSum([40, 11, 19, 17, -12], 28); // [ [ 17, 11 ], [ -12, 40 ] ] 20 | -------------------------------------------------------------------------------- /Algorithm/binarySearch.js: -------------------------------------------------------------------------------- 1 | function binarySearch(numArray, key) { 2 | let middleIdx = Math.floor(numArray.length / 2); 3 | let middleElem = numArray[middleIdx]; 4 | 5 | if (middleElem === key) return true; 6 | else if (middleElem < key && numArray.length > 1) { 7 | return binarySearch(numArray.splice(middleIdx, numArray.length), key); 8 | } else if (middleElem > key && numArray.length > 1) { 9 | return binarySearch(numArray.splice(0, middleIdx), key); 10 | } else return false; 11 | } 12 | 13 | binarySearch([5, 7, 12, 16, 36, 39, 42, 56, 71], 7); // true 14 | -------------------------------------------------------------------------------- /Algorithm/sieveOfEratosthenes.js: -------------------------------------------------------------------------------- 1 | function sieveOfEratosthenes(n) { 2 | let primes = []; 3 | for (let i = 0; i <= n; i++) { 4 | primes[i] = true; 5 | } 6 | 7 | primes[0] = false; 8 | primes[1] = false; 9 | 10 | for (let i = 2; i <= Math.sqrt(n); i++) { 11 | for (let j = 2; j * i <= n; j++) { 12 | primes[i * j] = false; 13 | } 14 | } 15 | 16 | let result = []; 17 | for (let i = 0; i < primes.length; i++) { 18 | if (primes[i]) result.push(i); 19 | } 20 | 21 | return result; 22 | } 23 | 24 | sieveOfEratosthenes(10); // [ 2, 3, 5, 7 ] 25 | -------------------------------------------------------------------------------- /Algorithm/maxStockProfit.js: -------------------------------------------------------------------------------- 1 | function maxStockProfit(pricesArr) { 2 | let maxProfit = -1; 3 | let buyPrice = 0; 4 | let sellPrice = 0; 5 | 6 | let changeBuyPrice = true; 7 | 8 | for (let i = 0; i < pricesArr.length; i++) { 9 | if (changeBuyPrice) buyPrice = pricesArr[i]; 10 | sellPrice = pricesArr[i + 1]; 11 | 12 | if (sellPrice < buyPrice) { 13 | changeBuyPrice = true; 14 | } else { 15 | let tempProfit = sellPrice - buyPrice; 16 | if (tempProfit > maxProfit) maxProfit = tempProfit; 17 | changeBuyPrice = false; 18 | } 19 | } 20 | 21 | return maxProfit; 22 | } 23 | 24 | maxStockProfit([10, 18, 4, 5, 9, 6, 16, 12]); // 12 25 | -------------------------------------------------------------------------------- /Algorithm/mergeSort.js: -------------------------------------------------------------------------------- 1 | function mergeSort(arr) { 2 | if (arr.length < 2) return arr; 3 | let middleIndex = Math.floor(arr.length / 2); 4 | let firstHalf = arr.slice(0, middleIndex); 5 | let secondHalf = arr.slice(middleIndex); 6 | 7 | return merge(mergeSort(firstHalf), mergeSort(secondHalf)); 8 | } 9 | 10 | function merge(arr1, arr2) { 11 | let result = []; 12 | while (arr1.length && arr2.length) { 13 | let minElem; 14 | if (arr1[0] < arr2[0]) minElem = arr1.shift(); 15 | else minElem = arr2.shift(); 16 | result.push(minElem); 17 | } 18 | 19 | if (arr1.length) result = result.concat(arr1); 20 | else result = result.concat(arr2); 21 | return result; 22 | } 23 | 24 | mergeSort([6000, 34, 203, 3, 746, 200, 984, 198, 764, 1, 9, 1]); // [ 1, 1, 3, 9, 34, 198, 200, 203, 746, 764, 984, 6000 ] 25 | -------------------------------------------------------------------------------- /Algorithm/caesarCipher.js: -------------------------------------------------------------------------------- 1 | function caesarCipher(str, num) { 2 | num = num % 26; 3 | let lowerCaseString = str.toLowerCase(); 4 | let alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); 5 | let newString = ''; 6 | 7 | for (let i = 0; i < lowerCaseString.length; i++) { 8 | let currentLetter = lowerCaseString[i]; 9 | if (currentLetter === ' ') { 10 | newString += currentLetter; 11 | continue; 12 | } 13 | let currentIndex = alphabet.indexOf(currentLetter); 14 | let newIndex = currentIndex + num; 15 | if (newIndex > 25) newIndex = newIndex - 26; 16 | if (newIndex < 0) newIndex = 26 + newIndex; 17 | if (str[i] === str[i].toUpperCase()) { 18 | newString += alphabet[newIndex].toUpperCase(); 19 | } 20 | else newString += alphabet[newIndex]; 21 | } 22 | 23 | return newString; 24 | } 25 | 26 | caesarCipher('Zoo Keeper', 2); // Bqq Mggrgt 27 | 28 | caesarCipher('Javascript', -900); // Bqq Mggrgt 29 | 30 | caesarCipher('Dhimas Akbar', 27); // Eijnbt Blcbs 31 | -------------------------------------------------------------------------------- /Algorithm/harmlessRansomNote.js: -------------------------------------------------------------------------------- 1 | function harmlessRansomNote(noteText, magazineText) { 2 | let noteArr = noteText.split(" "); 3 | let magazineArr = magazineText.split(" "); 4 | let magazineObj = {}; 5 | 6 | magazineArr.forEach(word => { 7 | if (!magazineObj[word]) magazineObj[word] = 0; 8 | magazineObj[word]++; 9 | }); 10 | 11 | let noteIsPossible = true; 12 | noteArr.forEach(word => { 13 | if (magazineObj[word]) { 14 | magazineObj[word]--; 15 | if (magazineObj[word] < 0) noteIsPossible = false; 16 | } else noteIsPossible = false; 17 | }); 18 | 19 | return noteIsPossible; 20 | } 21 | 22 | harmlessRansomNote( 23 | "this is a secret note for you from a secret admirer", 24 | "puerto rico is a place of great wonder and excitement it has many secret waterfall locations that i am an admirer of you must hike quite a distance to find the secret places as they are far from populated areas but it is worth the effort a tip i have for you is to go early in the morning when it is not so hot out also note that you must wear hiking boots this is one of the best places i have ever visited" 25 | ); 26 | -------------------------------------------------------------------------------- /DataStructures/bigOnotation.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 | // Linear runtime - Big O Notation: "O (n)" 11 | function logAll(array) { 12 | for (let i = 0; i < array.length; i++) { 13 | console.log(array[i]); 14 | } 15 | } 16 | 17 | logAll([1, 2, 3, 4, 5]); 18 | logAll([1, 2, 3, 4, 5, 6]); 19 | logAll([1, 2, 3, 4, 5, 6, 7]); 20 | 21 | // Exponential runtime - Big O Notation: "O (n^2)" 22 | function addAndLog(array) { 23 | for (let i = 0; i < array.length; i++) { 24 | for (let j = 0; j < array.length; j++) { 25 | console.log(array[i] + array[j]); 26 | } 27 | } 28 | } 29 | 30 | addAndLog(["A", "B", "C"]); // 9 pairs logged out 31 | addAndLog(["A", "B", "C", "D"]); // 16 pairs logged out 32 | addAndLog(["A", "B", "C", "D", "E"]); // 25 pairs logged out 33 | 34 | // Logarithmic runtime - Big O Notation: O (log n) 35 | function binarySearch(array, key) { 36 | let low = 0; 37 | let high = array.length - 1; 38 | let mid; 39 | let element; 40 | 41 | while (low <= high) { 42 | mid = Math.floor((low + high) / 2, 10); 43 | element = array[mid]; 44 | if (element < key) { 45 | low = mid + 1; 46 | } else if (element > key) { 47 | high = mid - 1; 48 | } else { 49 | return mid; 50 | } 51 | } 52 | return -1; 53 | } 54 | -------------------------------------------------------------------------------- /Algorithm/meanMedianMode.js: -------------------------------------------------------------------------------- 1 | function meanMedianMode(arr) { 2 | return { 3 | mean: getMean(arr), 4 | median: getMedian(arr), 5 | mode: getMode(arr) 6 | }; 7 | } 8 | 9 | function getMean(arr) { 10 | let sum = 0; 11 | 12 | arr.forEach(num => { 13 | sum += num; 14 | }); 15 | 16 | let mean = sum / arr.length; 17 | return mean; 18 | } 19 | 20 | function getMedian(arr) { 21 | arr.sort(function(a, b) { 22 | return a - b; 23 | }); 24 | let median; 25 | 26 | if (arr.length % 2 !== 0) { 27 | median = arr[Math.floor(arr.length / 2)]; 28 | } else { 29 | let mid1 = arr[arr.length / 2 - 1]; 30 | let mid2 = arr[arr.length / 2]; 31 | median = (mid1 + mid2) / 2; 32 | } 33 | 34 | return median; 35 | } 36 | 37 | function getMode(arr) { 38 | let modeObj = {}; 39 | 40 | arr.forEach(num => { 41 | if (!modeObj[num]) modeObj[num] = 0; 42 | modeObj[num]++; 43 | }); 44 | 45 | let maxFrequency = 0; 46 | let modes = []; 47 | for (let num in modeObj) { 48 | if (modeObj[num] > maxFrequency) { 49 | modes = [num]; 50 | maxFrequency = modeObj[num]; 51 | } else if (modeObj[num] === maxFrequency) modes.push(num); 52 | } 53 | 54 | if (modes.length === Object.keys(modeObj).length) modes = []; 55 | 56 | return modes; 57 | } 58 | 59 | meanMedianMode([1, 2, 3, 4, 5, 4, 6, 1]); // { mean: 3.25, median: 3.5, mode: [ '1', '4' ] } 60 | 61 | meanMedianMode([9, 10, 23, 10, 23, 9]); // mean: 14, median: 10, mode: [] } 62 | -------------------------------------------------------------------------------- /DataStructures/linkedList.js: -------------------------------------------------------------------------------- 1 | function LinkedList() { 2 | this.head = null; 3 | this.tail = null; 4 | } 5 | 6 | function Node(value, next, prev) { 7 | this.value = value; 8 | this.next = next; 9 | this.prev = prev; 10 | } 11 | 12 | LinkedList.prototype.addToHead = function(value) { 13 | let newNode = new Node(value, this.head, null); 14 | if (this.head) this.head.prev = newNode; 15 | else this.tail = newNode; 16 | this.head = newNode; 17 | }; 18 | 19 | LinkedList.prototype.addToTail = function(value) { 20 | let newNode = new Node(value, null, this.tail); 21 | if(this.tail) this.tail.next = newNode; 22 | else this.head = newNode; 23 | this.tail = newNode; 24 | } 25 | 26 | LinkedList.prototype.removeHead = function() { 27 | if(!this.head) return null; 28 | let val = this.head.value; 29 | this.head = this.head.next; 30 | if(this.head) this.head.prev = null; 31 | else this.tail = null; 32 | return val; 33 | } 34 | 35 | LinkedList.prototype.removeTail = function() { 36 | if(!this.tail) return null; 37 | let val = this.tail.value; 38 | this.tail = this.tail.prev; 39 | if(this.tail) this.tail.next = null; 40 | else this.head = null; 41 | return val; 42 | } 43 | 44 | LinkedList.prototype.search = function(searchValue) { 45 | let currentNode = this.head; 46 | while (currentNode) { 47 | if(currentNode.value === searchValue) return currentNode.value; 48 | currentNode = currentNode.next; 49 | } 50 | return null; 51 | } 52 | 53 | LinkedList.prototype.indexOf = function(value) { 54 | let indexes = []; 55 | let currentIndex = 0; 56 | let currentNode = this.head; 57 | while(currentNode) { 58 | if (currentNode.value === value) { 59 | indexes.push(currentIndex); 60 | } 61 | currentNode = currentNode.next; 62 | currentIndex++; 63 | } 64 | return indexes; 65 | }; 66 | 67 | 68 | let myLL = new LinkedList(); 69 | 70 | myLL.addToTail(1); 71 | myLL.addToTail(5); 72 | myLL.addToTail(3); 73 | myLL.addToTail(5); 74 | myLL.addToTail(8); 75 | myLL.addToTail(7); 76 | myLL.addToTail(5); 77 | 78 | console.log(myLL.indexOf(5)); -------------------------------------------------------------------------------- /DataStructures/hashTable.js: -------------------------------------------------------------------------------- 1 | function HashTable(size) { 2 | this.buckets = Array(size); 3 | this.numBuckets = this.buckets.length; 4 | } 5 | 6 | function HashNode(key, value, next) { 7 | this.key = key; 8 | this.value = value; 9 | this.next = next || null; 10 | } 11 | 12 | HashTable.prototype.hash = function(key) { 13 | let total = 0; 14 | for (let i = 0; i < key.length; i++) { 15 | total += key.charCodeAt(i); 16 | } 17 | let bucket = total % this.numBuckets; 18 | return bucket; 19 | } 20 | 21 | HashTable.prototype.insert = function(key, value) { 22 | let index = this.hash(key); 23 | if (!this.buckets[index]) this.buckets[index] = new HashNode(key, value); 24 | else if (this.buckets[index].key === key) { 25 | this.buckets[index].value = value; 26 | } 27 | else { 28 | let currentNode = this.buckets[index]; 29 | while (currentNode.next) { 30 | if (currentNode.next.key === key) { 31 | currentNode.next.value = value; 32 | return; 33 | } 34 | currentNode = currentNode.next; 35 | } 36 | currentNode.next = new HashNode(key, value); 37 | } 38 | } 39 | 40 | HashTable.prototype.get = function(key) { 41 | let index = this.hash(key); 42 | if (!this.buckets[index]) return null; 43 | else { 44 | let currentNode = this.buckets[index]; 45 | while (currentNode) { 46 | if (currentNode.key === key) return currentNode.value; 47 | currentNode = currentNode.next; 48 | } 49 | return null; 50 | } 51 | } 52 | 53 | HashTable.prototype.retrieveAll = function() { 54 | let allNodes = []; 55 | for (let i = 0; i < this.numBuckets; i++) { 56 | let currentNode = this.buckets[i]; 57 | console.log('awal', currentNode); 58 | while(currentNode) { 59 | console.log('while', currentNode); 60 | allNodes.push(currentNode); 61 | currentNode = currentNode.next; 62 | } 63 | } 64 | return allNodes; 65 | } 66 | 67 | let myHT = new HashTable(30); 68 | 69 | myHT.insert('Dean', 'dean@gmail.com'); 70 | myHT.insert('Megan', 'megan@gmail.com'); 71 | myHT.insert('Dane', 'dane@yahoo.com'); 72 | myHT.insert('Dean', 'deanmachine@gmail.com'); 73 | myHT.insert('Megan', 'megansmith@gmail.com'); 74 | myHT.insert('Dane', 'dane1010@outlook.com'); 75 | 76 | console.log(myHT.get('Megan')); -------------------------------------------------------------------------------- /DataStructures/binarySearchTree.js: -------------------------------------------------------------------------------- 1 | function BST(value) { 2 | this.value = value; 3 | this.left = null; 4 | this.right = null; 5 | } 6 | 7 | BST.prototype.insert = function(value) { 8 | if (value <= this.value) { 9 | if (!this.left) { 10 | this.left = new BST(value); 11 | } else { 12 | this.left.insert(value); 13 | } 14 | } else if (value > this.value) { 15 | if (!this.right) { 16 | this.right = new BST(value); 17 | } else { 18 | this.right.insert(value); 19 | } 20 | } 21 | }; 22 | 23 | BST.prototype.contains = function(value) { 24 | if (value === this.value) return true; 25 | else if (value < this.value) { 26 | if (!this.left) return false; 27 | else return this.left.contains(value); 28 | } else if (value > this.value) { 29 | if (!this.right) return false; 30 | else return this.right.contains(value); 31 | } 32 | }; 33 | 34 | BST.prototype.depthFirstTraversal = function(iteratorFunc, order) { 35 | if (order === "pre-order") iteratorFunc(this.value); 36 | if (this.left) this.left.depthFirstTraversal(iteratorFunc, order); 37 | if (order === "in-order") iteratorFunc(this.value); 38 | if (this.right) this.right.depthFirstTraversal(iteratorFunc, order); 39 | if (order === "post-order") iteratorFunc(this.value); 40 | }; 41 | 42 | BST.prototype.breadthFirstTraversal = function(iteratorFunc) { 43 | let queue = [this]; 44 | while (queue.length) { 45 | let treeNode = queue.shift(); 46 | iteratorFunc(treeNode); 47 | if (treeNode.left) queue.push(treeNode.left); 48 | if (treeNode.right) queue.push(treeNode.right); 49 | } 50 | }; 51 | 52 | BST.prototype.getMinVal = function() { 53 | if (this.left) return this.left.getMinVal(); 54 | else return this.value; 55 | }; 56 | 57 | BST.prototype.getMaxVal = function() { 58 | if (this.right) return this.right.getMaxVal(); 59 | else return this.value; 60 | }; 61 | 62 | let bst = new BST(50); 63 | 64 | bst.insert(30); 65 | bst.insert(70); 66 | bst.insert(100); 67 | bst.insert(60); 68 | bst.insert(59); 69 | bst.insert(20); 70 | bst.insert(45); 71 | bst.insert(35); 72 | bst.insert(85); 73 | bst.insert(105); 74 | bst.insert(10); 75 | 76 | function log(node) { 77 | console.log(node.value); 78 | } 79 | 80 | console.log('MIN: ', bst.getMinVal()); 81 | console.log('MAX: ', bst.getMaxVal()); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :star2: Javascript Alghorithms and Data Structures :star2: 2 | 3 | ## Algorithm : 4 | - [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) = a search algorithm that finds the position of a target value within a sorted array. 5 | 6 | - [Bubble Sort](https://en.wikipedia.org/wiki/Bubble_sort) = a simple sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order. 7 | 8 | - [Caesar Cipher](https://en.wikipedia.org/wiki/Caesar_cipher) = a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. 9 | 10 | - Fibonacci = the fibonacci sequence begins with 0 and 1. These are the first and second terms, respectively. After this, every element is the sum of the preceding elements. Given a number (position), calculate the fibonacci number at that position. 11 | 12 | - [Fizz Buzz](https://en.wikipedia.org/wiki/Fizz_buzz) = a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz". 13 | 14 | - Harmless Ransom Note = you have been given two strings. you have to find out whether you can make up the first string with the words present in the second string. 15 | 16 | - Is Palindrome = a number or string that is same after reverse. 17 | 18 | - Max Stock Profit = the cost of a stock on each day is given in an array, find the max profit that you can make by buying and selling in those days. 19 | 20 | - Mean Median Mode = calculate the mean, median and mode of those numbers and return the result as an object. 21 | 22 | - Memoized Fibonacci = the fibonacci algorithm that will run at an exponential runtime, the technique called memoization. 23 | 24 | - Merge Sort = Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. 25 | 26 | - Reverse Array in Place = manipulate array directly and return the result as its reverse. 27 | 28 | - Reverse Words = reverse the string without using array.prototype.reverse(). 29 | 30 | - Sieve Of Eratosthenes = given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. 31 | 32 | - Two Sum = calculate the pairs of numbers from the set that add up to the number. 33 | 34 | ## Data Structures 35 | - [Big O Notation](https://en.wikipedia.org/wiki/Big_O_notation) = a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity or in computer science to describe the performance or complexity of an algorithm.. 36 | 37 | - [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) = a node-based binary tree data structure that has properties. 38 | 39 | - [Constructor Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor) = a special method for creating and initializing an object created within a class. 40 | 41 | - [Hash Table](https://en.wikipedia.org/wiki/Hash_table) = a data structure that implements an associative array abstract data type, a structure that can map keys to values. 42 | 43 | - [Linked List](https://en.wikipedia.org/wiki/Linked_list) = a linear collection of data elements, whose order is not given by their physical placement in memory. 44 | 45 | - [Prototype Object Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype) = a property of the object constructor. And it is also the end of a prototype chain. 46 | 47 | - Recursion = the process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. --------------------------------------------------------------------------------