Last active
February 7, 2021 18:36
-
-
Save pfirpfel/baad08babda87116f6381f61938940ba to your computer and use it in GitHub Desktop.
MTG Wordiness
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 allPrintings = require('./allPrintings') // download from https://mtgjson.com/downloads/all-files/#AllPrintings | |
// takes a while to load | |
const sets = Object.entries(allPrintings.data) | |
const setsToCheck = sets.filter(set => ['core', 'masters', 'expansion'].includes(set[1].type)) | |
let wordiness = setsToCheck.map(set => { | |
let setSize = set[1].baseSetSize | |
let cards = set[1].cards.filter(card => Number.parseInt(card.number) <= setSize) | |
let words = cards.filter(c => typeof c.text !== 'undefined').reduce((acc, curr) => { return acc + curr.text.split(/\s/).length }, 0) | |
return { set: set[1].name, wpc: words / cards.length} // cards.length > setSize because of double faced cards | |
}) | |
// sort by highest first | |
wordiness.sort((a, b) => b.wpc - a.wpc) | |
let csv = wordiness.reduce((txt, entry) => txt + entry.set + ',' + entry.wpc + '\n', '') | |
const fs = require('fs'); | |
fs.writeFile('wordiness.csv', csv, (err) => { | |
if (err) throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment