### re: Daily Challenge #21 - Human Readable Time VIEW POST

Javascript (no idea whether this works or not :D )

const quoAndRem = (divd,div) => {
let rem = divd % div
let quo = (divd - rem)/div

return [quo,rem]
}

const formatter = (...vals) => {
const output = vals.map((itm,indx) => {
let unit
switch (indx) {
case 0:
unit = "year"
break;
case 1:
unit = "day"
break;
case 2:
unit = "hour"
break;
case 3:
unit = "minute"
break;
case 4:
unit = "second"
break;
}

if (indx !== 1) {
unit += "s"
}

return [itm,unit]
}).filter(itm => itm !== 0).reduce((accm,curr,indx,arr) => {
if (indx < arr.length - 2) {
return ${accm}${curr} ${curr},  } else if (indx === arr.length - 2) { return ${accm}${curr}${curr} and
} else {
return ${accm}${curr} \${curr}
}
},"");

return output
}

const yearInSecs = 365*24*60*60
const dayInSecs = 24*60*60
const hourInSecs = 60*60
const minInSecs = 60
const secInSecs = 1

let yearVal = quoAndRem(seconds, yearInSecs)
let dayVal = quoAndRem(yearVal, dayInSecs)
let hourVal = quoAndRem(dayVal, hourInSecs)
let minVal = quoAndRem(hourVal, minInSecs)
let secVal = quoAndRem(minVal, secInSecs)

output = formatter(yearVal,dayVal,hourVal,minVal,secVal)

return output
}  