Skip to content

Instantly share code, notes, and snippets.

@MineRobber9000
Last active December 8, 2018 05:33
Show Gist options
  • Save MineRobber9000/0e14cddcf55fd6e83aafda69749509f8 to your computer and use it in GitHub Desktop.
Save MineRobber9000/0e14cddcf55fd6e83aafda69749509f8 to your computer and use it in GitHub Desktop.
MRANK function for Google Sheets
function MRANK(value,values) {
var values = values.map(function(x) { return x[0]; }); // apparently I misjudged how Google Sheets passes values. Why is it like this?!?!
var valuesSorted = values.sort(function(a,b){ return b-a; });
var valuesUnique = valuesSorted.filter(function(value,index,self) { return self.indexOf(value) === index; });
var index = valuesUnique.indexOf(value);
if (index<0) {
throw("MRANK has no valid input data");
}
return index+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment