Created
November 14, 2020 08:14
-
-
Save ollie314/939bf37bc5fb69401ed2cbb153a45693 to your computer and use it in GitHub Desktop.
Simple implementation of last step of the random condorcet toss
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 echo = m => console.log(m); | |
const rand = (max, min = 0) => Math.ceil(Math.random() * (max - min) + min); | |
const even = x => x % 2 == 0; | |
const rank = (stack) => { | |
const f = (b) => { | |
if(b.length == 0) return; // shouldn't happens | |
if(b.length == 1) { | |
echo(b[0]); | |
return; | |
} | |
const x = rand(b.length - 1); | |
const p = b[x]; | |
echo(p); | |
f(b.filter((v, i) => i !== x)); | |
}; | |
stack.forEach(e => f(e)); | |
}; | |
// example | |
rank([[1], [2, 3, 4], [5, 6, 8]]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment