Skip to content

Instantly share code, notes, and snippets.

View markmelville's full-sized avatar

Mark Melville markmelville

  • Ancestry
  • Lehi, UT
View GitHub Profile
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* Examples of some best practices
@markmelville
markmelville / percentile.js
Last active September 21, 2016 14:38 — forked from IceCreamYou/percentile.js
Utility functions to calculate percentiles and percent ranks in a JavaScript array.
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
arr.concat().sort((a,b) => a-b);
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];
var index = (arr.length - 1) * p,