JSFiddle - React, Tailwind, and code Playground
by Alexander Malinov
JavaScript
const isTimeValid = (time) => !!time.match(/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/);
const formatWithZero = (number) => number < 10 ? `0${number}` : `${number}`;
const flipTime = (time) => time.split('').reverse().map((digit) => {
switch (digit) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 5;
case '5':
return 2;
case '8':
return 8;
case ':':
return ':';
default:
return '#'
}
}).join('');
for (let h = 0; h < 24; h++) {
for (let m = 0; m < 60; m++) {
const time = `${formatWithZero(h)}:${formatWithZero(m)}`;
const flippedTime = flipTime(time);
isTimeValid(flippedTime) && console.log(time, flippedTime);
}
}