0
0
Fork 0

Add jsdoc comments...

This commit is contained in:
Oliver-Akins 2023-02-24 10:47:20 -07:00
parent 9b26f60af0
commit a9194fa956

View file

@ -1,3 +1,15 @@
export type key = {[index: string]: number[]}
/**
* Takes a guess and adds it into the game board, this is equivalent to writing
* the letter above the underscore, without keeping the underscore.
*
* @param key An object with keys of single letters, and their indexes in the
* solution that they were removed from
* @param current The player's current game board
* @param letter The letter that is being added
* @returns The updated game board
*/
export function addLetter(key: any, current: string, letter: string) {
let indexes = key[letter];
for (const i of indexes) {
@ -6,8 +18,15 @@ export function addLetter(key: any, current: string, letter: string) {
return current;
};
export function convertToKey(phrase: string) {
let key: {[index: string]: number[]} = {};
/**
* Creates the key object so we can update the game board easier
*
* @param phrase The already-spaced phrase
* @returns An object with the keys as a single letter, and the value as an array
* of integers that the letter appears at
*/
export function convertToKey(phrase: string): key {
let key: key = {};
for (var i = 0; i < phrase.length; i++) {
let letter = phrase[i].toUpperCase();
if (!letter.match(/[a-zA-Z]/)) { continue };
@ -19,6 +38,13 @@ export function convertToKey(phrase: string) {
return key;
};
/**
* Creates a copy of the phrase string that has all English alphabet characters
* replaced with underscores
*
* @param phrase The phrase to make anonymous
* @returns The anonymized phrase
*/
export function anonymizePhrase(phrase: string) {
let anon = ``;
for (const letter of phrase) {
@ -31,6 +57,13 @@ export function anonymizePhrase(phrase: string) {
return anon;
};
/**
* Creates a copy of the phrase and puts spaces between each character and replaces
* spaces from the original phrase with a special character
*
* @param phrase The phrase to space apart
* @returns A copy of the phrase with extra spaces
*/
export function spacePhrase(phrase: string) {
let spaced = ``;
for (const letter of phrase) {