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
def partition (array, start, end): | |
pivot = array[start] | |
low = start + 1 | |
high = end | |
while (low <= high): | |
while (low <= end and array[low] <= pivot): | |
low += 1 | |
while (high > start and array[high] > pivot): | |
high -= 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
def merge_two(arr1, arr2): | |
merged = [] | |
arr1_index = 0 | |
arr2_index = 0 | |
arr1_size = len(arr1) | |
arr2_size = len(arr2) | |
while (arr1_index < arr1_size and arr2_index < arr2_size): | |
if (arr1[arr1_index] < arr2[arr2_index]): |
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
def heapify(array): | |
last_index = len(array) - 1 | |
for index in range(last_index, -1, -1): | |
bubble_down(array, index) | |
def bubble_down(array, index): | |
index_limit = len(array) - 1 | |
lchild_index = (index + 1) * 2 - 1 | |
rchild_index = lchild_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
<div (click)="handleAction($event)"> | |
<div *ngFor="let item of listing"> | |
<div>{{ item.label }}</div> | |
<div> | |
<button [attr.data-id]="item.id" | |
data-action="modify"> | |
Modify | |
</button> | |
<button [attr.data-id]="item.id" | |
data-action="delete"> |
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
/** | |
* as (typeof []) is "object" | |
*/ | |
function MyArray() { | |
const array = Object.create(MyArray.prototype); | |
Object.defineProperty(array, 'length', { | |
value: 0, | |
enumerable: false, | |
writable: 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
const log = console.log; | |
function map(fn) { | |
return function* (arr) { | |
for (const el of arr) { | |
yield fn(el); | |
} | |
} | |
} |
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
public class String { | |
public static boolean contains(String s, String t) { | |
for (int i = 0; i < s.length(); i++) { | |
if (s.charAt(i) == t.charAt(0)) { | |
int j = 1; | |
for (; j < t.length(); j++) { | |
if (t.charAt(j) != s.charAt(i + j)) { | |
break; | |
} |
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
/** Person pseudo class. */ | |
const Person = (function () { | |
function Person(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
Person.prototype.alias = function () { | |
return this.firstName.charAt(0) + this.lastName.charAt(0); | |
} |
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
const map = ([head, ...tail], fn) => | |
typeof head === 'undefined' ? | |
[] : | |
[fn(head), ...map(tail, fn)]; | |
const reduce = ([head, ...tail], fn, value) => | |
typeof head === 'undefined' ? | |
value : | |
reduce(tail, fn, fn(value, head)); |
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
import java.util.Arrays; | |
/** | |
* MAX_HEAP: the root will always be the largest value | |
*/ | |
public class MaxHeap { | |
private int[] data; | |
private int size; | |
public MaxHeap(int size) { |