This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ScriptoniteSort() { | |
| this.arr = []; | |
| } | |
| ScriptoniteSort.prototype = { | |
| swap: function(arr, index_one, index_two) { | |
| //swap | |
| var temp = arr[index_one]; | |
| arr[index_one] = arr[index_two]; | |
| arr[index_two] = temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ScriptoniteSort() { | |
| this.arr = []; | |
| } | |
| ScriptoniteSort.prototype = { | |
| swap: function(arr, index_one, index_two) { | |
| //swap | |
| var temp = arr[index_one]; | |
| arr[index_one] = arr[index_two]; | |
| arr[index_two] = temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myList = [1, 3, 5, 7, 9]; | |
| function binarySearch(myList, itemToFind) { | |
| var low = 0, | |
| high = myList.length - 1, | |
| mid, | |
| guessed; | |
| while(low <= high) { | |
| mid = Math.floor((low + high) / 2), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var items = [2, 5, 3, 7, 8, 10, 15, 18, 24, 111, 12, 19, 87]; | |
| function itemSearch(itemToFind) { | |
| items.forEach(function(itemValue, index, array){ | |
| if(itemValue === itemToFind) { | |
| //as long as the current index value is not the first index in the array | |
| if(index > 0) { | |
| selfOrganize(array, index, index -1); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var items = [2, 5, 3, 7, 8, 10, 15, 18, 24, 111, 12, 19, 87]; | |
| //Returns the Min Value | |
| function findMinValue(items){ | |
| var currentMin = items[0]; | |
| items.forEach(function(item){ | |
| if(currentMin > item) { | |
| currentMin = item; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Using a for loop | |
| var items = [2, 5, 3, 7, 8, 10, 15, 18, 24, 111, 12, 19, 87]; | |
| function itemSearch(item) { | |
| for(var i=0; i < items.length; i++) { | |
| if(items[i] === item) { | |
| console.log("Found item " + item + " at index " + i); | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //ES5 VERSION | |
| DFS : function(v, color) { | |
| //change the color to grey | |
| color[v] = 'grey'; | |
| //get its adjacency list | |
| var curVertexAdjLst = this.getAdjacencyListVertex(v); | |
| var that = this; | |
| curVertexAdjLst.forEach(function(listVertex){ | |
| if(color[listVertex] === 'white') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //ES5 VERSION | |
| function Graph() { | |
| this.vertices = []; | |
| this.adjacentList = new Map(); | |
| this.numberOfEdges = 0; | |
| } | |
| Graph.prototype = { | |
| /* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //ES5 Version | |
| function Graph() { | |
| this.vertices = []; | |
| this.adjacentList = new Map(); | |
| } | |
| Graph.prototype = { | |
| /* | |
| other methods go here | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Graph() { | |
| this.vertices = []; | |
| this.adjacentList = new Map(); | |
| } | |
| Graph.prototype = { | |
| /* | |
| other methods go here | |
| */ |