0
0
Fork 0

Add endpoints and game utilities

This commit is contained in:
Oliver Akins 2022-12-25 16:52:15 -06:00
parent 56f2195962
commit 6a174e4d36
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
7 changed files with 213 additions and 1 deletions

46
src/utils/game.ts Normal file
View file

@ -0,0 +1,46 @@
export function addLetter(key: any, current: string, letter: string) {
let indexes = key[letter];
for (const i of indexes) {
current = current.slice(0, i) + letter.toUpperCase() + current.slice(i+1);
};
return current;
};
export function convertToKey(phrase: string) {
let key: {[index: string]: number[]} = {};
for (var i = 0; i < phrase.length; i++) {
let letter = phrase[i].toUpperCase();
if (!letter.match(/[a-zA-Z]/)) { continue };
if (key[letter] == null) {
key[letter] = [];
};
key[letter].push(i);
};
return key;
};
export function anonymizePhrase(phrase: string) {
let anon = ``;
for (const letter of phrase) {
if (letter.match(/[A-Za-z]/)) {
anon += `_`;
} else {
anon += letter;
};
};
return anon;
};
export function spacePhrase(phrase: string) {
let spaced = ``;
for (const letter of phrase) {
if (letter.match(/[A-Za-z]/)) {
spaced += `${letter} `;
} else if (letter == ` `) {
spaced += ``;
} else {
spaced += letter;
};
};
return spaced;
};