Created
August 9, 2020 02:35
-
-
Save cplpearce/6033ca5753f5304802d2169cc68d6c06 to your computer and use it in GitHub Desktop.
Kata 10 - Talking Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const talkingCalendar = function(date) { | |
const dateArray = date.split('/'); | |
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; | |
let friendlyDate = {day : 0, month : '', year : 0}; | |
friendlyDate.day = +dateArray[2] + (+dateArray[2] === 1 ? 'st' : (+dateArray[2] === 2 ? 'nd' : +dateArray[2] === 3 ? 'rd' : 'th')); | |
friendlyDate.month = months[(+dateArray[1]) - 1]; | |
friendlyDate.year = dateArray[0]; | |
return (`${friendlyDate.month} ${friendlyDate.day}, ${friendlyDate.year}` ) | |
} | |
console.log(talkingCalendar("2017/12/02")); | |
console.log(talkingCalendar("2007/11/11")); | |
console.log(talkingCalendar("1987/08/24")); | |
/* | |
Output | |
December 2nd, 2017 | |
November 11th, 2007 | |
August 24th, 1987 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment