Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Split, ternary solution in Clear category for [old] Time Converter (24h to 12h) by zoezed
"use strict";
function timeConverter(dayTime) {
let [h, mins] = dayTime.split(':')
return (h == 0 ? 12 : h > 12 ? h-12 : h | 0) + ':' + mins + (h < 12 ? ' a.m.' : ' p.m.')
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(timeConverter('12:30'))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(timeConverter('12:30'), '12:30 p.m.')
assert.equal(timeConverter('09:00'), '9:00 a.m.')
assert.equal(timeConverter('23:15'), '11:15 p.m.')
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Feb. 12, 2020