Skip to content

Instantly share code, notes, and snippets.

@JCGrant
Created August 26, 2016 22:02
Show Gist options
  • Save JCGrant/8eb153dc07c46383174d8b8f3ad087f7 to your computer and use it in GitHub Desktop.
Save JCGrant/8eb153dc07c46383174d8b8f3ad087f7 to your computer and use it in GitHub Desktop.
A script which will play http://guessthecorrelation.com/ for you
/*
* Copy and paste the following code after clicking
* NEW GAME at http://guessthecorrelation.com.
* Tested and works in Chrome. Not sure about other
* browsers due to usage of ES6 features.
*/
const parseTransformStringIntoPoint = (transformString) => {
let splitString = transformString.split(',');
let xString = splitString[0].substring(10, splitString[0].length);
let yString = splitString[1].substring(0, splitString[1].length - 1);
return [parseFloat(xString), parseFloat(yString)];
};
const extractData = () => {
let nvPoints = document.getElementsByClassName('nv-point');
let ps = [...nvPoints]
.map(point => point.getAttribute('transform'))
.map(parseTransformStringIntoPoint);
let xs = ps.map(p => p[0]);
let ys = ps.map(p => p[1]);
return [xs, ys];
};
const run = () => {
let [xs, ys] = extractData();
let coefficient = jStat.corrcoeff(xs, ys);
document.getElementById('guess-input').value = Math.abs(coefficient);
document.getElementById('submit-btn').click();
document.getElementById('next-btn').click();
};
setInterval(run, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment