Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Last active July 24, 2023 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grubba27/2d65c09bcf2a138928e08ee8b46c817a to your computer and use it in GitHub Desktop.
Save Grubba27/2d65c09bcf2a138928e08ee8b46c817a to your computer and use it in GitHub Desktop.
find possiblities
// given a string, list the possible cenarios for each character, given that if the word has a
// ? it should be either "E" or "U"
// example: "???" -> ["EEE", "EEU", "EUE", "EUU", "UEE", "UEU", "UUE", "UUU"]
// example: "??U" -> ["EEU", "EUU", "UEU", "UUU"]
// example "fo?" -> ["foE", "foU"]
/**
*
* @param {string} str
* @returns {string[]}
*/
function questionMark(str) {
// implement
}
/**
*
* @param {string} name
* @param { } callback
*/
function assement(name, callback) {
let counter = 0,
failed = 0,
errorList = [];
console.log("Starting the program");
/**
*
* @param {any} expected
* @param {any} actual
* @returns {void}
*/
const assert = (expected, actual) => {
counter++;
if (expected !== actual) {
failed++;
errorList.push(new Error(`Expected ${expected} but got ${actual}`));
}
};
callback(assert);
console.log(`Total tests: ${counter}, Failed: ${failed}`);
if (failed > 0) {
console.log("Errors:");
errorList.forEach((err) => console.log(err.message));
}
}
void (function () {
assement("questionMark", (assert) => {
assert(
["EEE", "EEU", "EUE", "EUU", "UEE", "UEU", "UUE", "UUU"],
questionMark("???")
);
assert(["EEU", "EUU", "UEU", "UUU"], questionMark("??U"));
assert(["foE", "foU"], questionMark("fo?"));
});
console.log("Program finished");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment