Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Cómo convertir segundos a la unidad de tiempo significativa más grande

¿Cuál sería la forma más limpia de convertir una cantidad de segundos a la unidad más grande que no sea 0 y luego mostrar solo la unidad significativa?

 Input -> Expected output 1 -> 1s 61 -> 1m 120 -> 2m 3620 -> 1h 86400 -> 1day
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 const units = [ [1, "s"], [60, "m"], [60 * 60, "h"], [60 * 60 * 24, "day"] ]; function displayTime(seconds) { let bestUnit = units[0]; for(const unit of units) { if(seconds >= unit[0]) { bestUnit = unit; } } const [divisor, label] = bestUnit; return Math.floor(seconds /divisor) + label; } console.log(displayTime(1)); // 1s console.log(displayTime(61)); // 1m console.log(displayTime(120)); // 2m console.log(displayTime(3620)); // 1h console.log(displayTime(86400)); // 1day

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!