Javascript (no idea whether this works or not :D )
constquoAndRem=(divd,div)=>{letrem=divd%divletquo=(divd-rem)/divreturn[quo,rem]}constformatter=(...vals)=>{constoutput=vals.map((itm,indx)=>{letunitswitch(indx){case0:unit="year"break;case1:unit="day"break;case2:unit="hour"break;case3:unit="minute"break;case4:unit="second"break;}if(indx!==1){unit+="s"}return[itm,unit]}).filter(itm=>itm[0]!==0).reduce((accm,curr,indx,arr)=>{if(indx<arr.length-2){return`${accm}${curr[0]}${curr[1]}, `}elseif(indx===arr.length-2){return`${accm}${curr[0]}${curr[1]} and `}else{return`${accm}${curr[0]}${curr[1]}`}},"");returnoutput}functionreadableTime(seconds){constyearInSecs=365*24*60*60constdayInSecs=24*60*60consthourInSecs=60*60constminInSecs=60constsecInSecs=1letyearVal=quoAndRem(seconds,yearInSecs)letdayVal=quoAndRem(yearVal[1],dayInSecs)lethourVal=quoAndRem(dayVal[1],hourInSecs)letminVal=quoAndRem(hourVal[1],minInSecs)letsecVal=quoAndRem(minVal[1],secInSecs)output=formatter(yearVal[0],dayVal[0],hourVal[0],minVal[0],secVal[0])returnoutput}console.log(readableTime(60))
I may change the formatter function to be more elegant and less crappy using slice and arrays and idontknow.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Javascript (no idea whether this works or not :D )
I may change the formatter function to be more elegant and less crappy using slice and arrays and idontknow.