Skip to content

Instantly share code, notes, and snippets.

@BlakeDonn
Last active September 11, 2024 19:09
Show Gist options
  • Save BlakeDonn/2d5ac3053117e14be0abbe76fa2b2210 to your computer and use it in GitHub Desktop.
Save BlakeDonn/2d5ac3053117e14be0abbe76fa2b2210 to your computer and use it in GitHub Desktop.
const inputs = [
'00:00', '00:12', '01:00', '06:01', '06:18',
'06:30', '10:34', '12:00', '12:09', '23:23'
];
const expectedOutputs = [
"midnight", "twelve twelve am", "one o'clock am", "six oh one am",
"six ten am", "six eighteen am", "six thirty am", "ten thirty four am",
"noon", "twelve oh nine pm", "eleven twenty three pm"
];
const timeToWord = (input) => {
if (input === '00:00') return 'midnight';
if (input === '12:00') return 'noon';
// Additional logic needed to handle other time inputs
};
const testResults = (inputs) => {
let totalCorrect = 0, totalIncorrect = 0;
inputs.forEach((input, i) => {
console.log(`Testing input ${input}`);
const result = timeToWord(input);
if (result === expectedOutputs[i]) {
console.log(`${input} converted to ${result} correctly`);
totalCorrect++;
} else {
console.log(`${input} incorrectly converted to ${result}`);
totalIncorrect++;
}
});
console.log(`Total Correct: ${totalCorrect}`);
console.log(`Total Incorrect: ${totalIncorrect}`);
};
testResults(inputs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment