Add jsdoc comments...
This commit is contained in:
parent
9b26f60af0
commit
a9194fa956
1 changed files with 35 additions and 2 deletions
|
|
@ -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) {
|
export function addLetter(key: any, current: string, letter: string) {
|
||||||
let indexes = key[letter];
|
let indexes = key[letter];
|
||||||
for (const i of indexes) {
|
for (const i of indexes) {
|
||||||
|
|
@ -6,8 +18,15 @@ export function addLetter(key: any, current: string, letter: string) {
|
||||||
return current;
|
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++) {
|
for (var i = 0; i < phrase.length; i++) {
|
||||||
let letter = phrase[i].toUpperCase();
|
let letter = phrase[i].toUpperCase();
|
||||||
if (!letter.match(/[a-zA-Z]/)) { continue };
|
if (!letter.match(/[a-zA-Z]/)) { continue };
|
||||||
|
|
@ -19,6 +38,13 @@ export function convertToKey(phrase: string) {
|
||||||
return key;
|
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) {
|
export function anonymizePhrase(phrase: string) {
|
||||||
let anon = ``;
|
let anon = ``;
|
||||||
for (const letter of phrase) {
|
for (const letter of phrase) {
|
||||||
|
|
@ -31,6 +57,13 @@ export function anonymizePhrase(phrase: string) {
|
||||||
return anon;
|
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) {
|
export function spacePhrase(phrase: string) {
|
||||||
let spaced = ``;
|
let spaced = ``;
|
||||||
for (const letter of phrase) {
|
for (const letter of phrase) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue