Skip to content

Instantly share code, notes, and snippets.

@stevengoldberg
stevengoldberg / nthMax.js
Last active August 29, 2015 14:27
An ES6 utility function for finding the nth-max value in an array
/**
* An ES6 utility function for finding the nth-max value in an array.
*/
let nthMax = (array, nth = 1) => {
if(nth > (array.length - 1)) {
throw new Error('Nth max value exceeds array size');
}
let newArr = array,
i = 0;
@stevengoldberg
stevengoldberg / bst.js
Last active March 16, 2020 13:02
ES6 functions for manipulating a Binary Search Tree
/*
* Based on the work of Nicholas C. Zakas
* https://github.com/nzakas/computer-science-in-javascript/
*/
class Node {
constructor(value = null, left = null, right = null) {
this.value = value;
this.right = right;
this.left = left;