Last active
June 11, 2023 22:29
-
-
Save well1791/64c37fa933d6942588a90cee82b939c9 to your computer and use it in GitHub Desktop.
get bigrams
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
// see: http://norvig.com/mayzner.html | |
all = [...document.querySelectorAll('tbody td')] | |
.filter((td) => td.title.includes(": ")) | |
.map((td) => { | |
const [bi, val] = td.title | |
.split('%')[0] | |
.split(': ') | |
return [bi.toLowerCase(), Number(val)] | |
}) | |
.filter(([bi]) => !/(.)\1/.test(bi)) | |
.sort(([, a], [, b]) => a > b ? -1 : 1) | |
allR = Object.entries(all.reduce((z, [bi, valToAdd]) => { | |
const [left, right] = bi.split('') | |
const triLR = [right + bi, bi + left] | |
const [triL, triR] = triLR | |
const tri = triLR.every((triX) => z[triX] === undefined) | |
? triL | |
: (z[triL] !== undefined ? triL : triR) | |
return { | |
...z, | |
[tri]: (z[tri] || 0 ) + valToAdd, | |
} | |
}, {})) | |
.sort(([, a], [, b]) => a > b ? -1 : 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment