Skip to content

Instantly share code, notes, and snippets.

@esnho
Created November 15, 2021 21:17
Show Gist options
  • Save esnho/6dccbbc248bdb2799a75a0e277a4fd3e to your computer and use it in GitHub Desktop.
Save esnho/6dccbbc248bdb2799a75a0e277a4fd3e to your computer and use it in GitHub Desktop.
rarity hypothesis
let editionCount;
// count the editions
editionCount = window.localStorage.getItem('editionCount');
editionCount = editionCount ? Number(editionCount) + 1 : 1;
window.localStorage.setItem('editionCount', editionCount);
// create inspector
const inspector = document.createElement('div');
inspector.style.width = '100%';
inspector.style.backgroundColor = 'rgb(255,255,255,0.6)';
const rarities = []
// read all features
for (const feature in window.$fxhashFeatures) {
const value = window.$fxhashFeatures[feature];
pushValue(feature, value);
const rarity = getValuePercentage(feature, value);
rarities.push(rarity);
const feat = document.createElement('div');
feat.textContent = `%${rarity} - ${feature}: ${value}`;
inspector.appendChild(feat);
}
const getMax = (a, b) => Math.max(a, b);
const getMin = (a, b) => Math.min(a, b);
const getSum = (a, b) => a + b;
const max = rarities.reduce(getMax, 0);
const min = rarities.reduce(getMin, 110);
const mean = rarities.reduce(getSum, 0) / rarities.length;
const minDiv = document.createElement('div');
minDiv.textContent = `minimum rarity ${min}`;
inspector.appendChild(minDiv);
const meanDiv = document.createElement('div');
meanDiv.textContent = `mean rarity ${mean}`;
inspector.appendChild(meanDiv);
const maxDiv = document.createElement('div');
maxDiv.textContent = `max rarity ${max}`;
inspector.appendChild(maxDiv);
const button = document.createElement('button');
button.onclick = () => {
window.localStorage.clear();
}
button.textContent = "CLEAR COUNT";
inspector.appendChild(button);
document.body.appendChild(inspector);
function pushValue(id, value) {
let current = window.localStorage.getItem(id);
if (!current) {
current = {};
} else {
current = JSON.parse(current);
}
current[value] = current[value] ? Number(current[value]) + 1 : 1;
window.localStorage.setItem(id, JSON.stringify(current));
}
function getValuePercentage(id, value) {
let current = window.localStorage.getItem(id);
current = JSON.parse(current);
const tot = current[value] / editionCount;
return Math.round(tot * 10000) / 100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment