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
$(document).click(function(e) { | |
let container = $("YOUR_CONTAINER_SELECTOR"); | |
// if the target of the click isn't the container nor a descendant of the container | |
if (!container.is(e.target) && container.has(e.target).length === 0) { | |
container.hide(); | |
} | |
}); |
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 addScript(url) { | |
const tag = document.createElement("script") | |
tag.type = "text/javascript" | |
tag.src = url | |
document.body.appendChild(tag) | |
} |
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
// start at the beginning of the array and iterate through to the second to last item | |
for (int currentIndex = 0; currentIndex < array.length - 1; currentIndex++) | |
{ | |
// assume the currentIndex is the smallest | |
int minIndex = currentIndex; | |
// set i to be the index immediately proceeding the currentIndex | |
for (int i = currentIndex + 1; i < array.length; i++) | |
{ | |
// if true, we found a smaller index | |
if (array[i] < array[minIndex]) |
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
/** | |
* Generates a string containing all of the edges in the tree rooted at "this" node, in DOT format. | |
* Assumes this node has member variables called “data”, “leftChild”, and “rightChild”. | |
* | |
* @return DOT format string to enter at http://www.webgraphviz.com | |
*/ | |
public String generateDot() throws Exception | |
{ | |
// `root` represents the root node of the binary search tree | |
if (root == null) |
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
void mergeSort(final ArrayList list, final int start, final int end) | |
{ | |
if (start >= end) | |
return; | |
int middle = (start + end) / 2; | |
mergeSort(list, start, middle); // Sort the left side of the list | |
mergeSort(list, middle + 1, end); // Sort the right side of the list | |
merge(list, new ArrayList<>(list.size()), start, middle + 1, end + 1); // Merge both sides |
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
void selectionSort(int[] array) | |
{ | |
for (int i = 0; i < array.length - 1; i++) | |
{ | |
int index = i; | |
for (int j = i + 1; j < array.length; j++) | |
if (array[j] < array[index]) | |
index = j; | |
int temp = array[i]; |
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
void insertionSort(int[] array) | |
{ | |
for (int i = 1; i < array.length; i++) | |
{ | |
int index = i, indexValue = array[index]; | |
while (index > 0 && array[index - 1] > indexValue) array[index] = array[--index]; | |
array[index] = indexValue; | |
} |
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
$('a[href*="#"]') | |
// Remove links that don't actually link to anything | |
.not('[href="#"]') | |
.not('[href="#0"]') | |
.click(function(event) { | |
// On-page links | |
if ( | |
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') | |
&& | |
location.hostname == this.hostname |
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
/** | |
* We figured out part of the answer to our question. | |
* So now we'd just like to know if we're on the right track. | |
*/ | |
public void insert(int index, E data) | |
{ | |
ensureCapacity(indexCounter + 1); | |
for (int i = elementData.length; i > index; i--) |
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
$('#menu').on('DOMMouseScroll mousewheel', function(ev) { | |
var $this = $(this), | |
scrollTop = this.scrollTop, | |
scrollHeight = this.scrollHeight, | |
height = $this.height(), | |
delta = (ev.type == 'DOMMouseScroll' ? | |
ev.originalEvent.detail * -40 : | |
ev.originalEvent.wheelDelta), | |
up = delta > 0; |
NewerOlder