Created
June 4, 2018 10:34
-
-
Save amrza/7bb4913d8084340b26d8685d11ad26d7 to your computer and use it in GitHub Desktop.
This file contains 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
function between(number, start, end) { | |
return number >= start && number <= end; | |
} | |
function makeWidth(day) { | |
if (between(day, 1, 9)) { return day + " " } | |
if (between(day, 10, 31)) { return day + " " } | |
return " "; | |
} | |
function addDay(row, day) { | |
return row + makeWidth(day); | |
} | |
function makeDaysRow(days) { | |
return days.reduce(addDay, ""); | |
} | |
function addDaysRowToTable(table, days) { | |
return table + makeDaysRow(days) + "\n"; | |
} | |
function daysTable(year, month) { | |
return jalaali.monthMatrix(year, month).reduce(addDaysRowToTable, ""); | |
} | |
function daysTableHeader() { | |
return "J P Ch Se D Y S\n" | |
+ "--------------------------------------\n"; | |
} | |
/** | |
* Representation of a Month, in the form of a textual table. | |
* | |
* @example monthTable(1397, 1) | |
* | |
* J P Ch Se D Y S | |
* -------------------------------------- | |
* 3 2 1 | |
* 10 9 8 7 6 5 4 | |
* 17 16 15 14 13 12 11 | |
* 24 23 22 21 20 19 18 | |
* 31 30 29 28 27 26 25 | |
*/ | |
function monthTable(year, month) { | |
return daysTableHeader() + daysTable(year, month); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment