- Use the modulo operator (%) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
//#Source https://bit.ly/2neWfJ2 const get_Meridiem_Suffix_Of_Integer = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 ? 12 + 'pm' : num < 12 ? (num % 12) + 'am' : (num % 12) + 'pm'; console.log(get_Meridiem_Suffix_Of_Integer(0)); console.log(get_Meridiem_Suffix_Of_Integer(11)); console.log(get_Meridiem_Suffix_Of_Integer(13)); console.log(get_Meridiem_Suffix_Of_Integer(25));
12am 11am 1pm 1pm
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join