Skip to content

Instantly share code, notes, and snippets.

@tkhatibi
Forked from amrza/cal-jalaali.js
Last active May 29, 2018 21:26
Show Gist options
  • Select an option

  • Save tkhatibi/655bb20b93c3a667b3da31d4a49a9ffc to your computer and use it in GitHub Desktop.

Select an option

Save tkhatibi/655bb20b93c3a667b3da31d4a49a9ffc to your computer and use it in GitHub Desktop.
/**
* @param {number|string} value
* @returns {string}
*/
const getPrintableElement = (value) => value + " ";
/**
* @param {number} day
* @returns {string}
*/
const getPrintableDay = (day) => getPrintableElement((
(day === 0 && " ") ||
(day < 10 && " ") ||
(day)
));
/**
* @param {number[]} days
* @returns {string}
*/
const getPrintableRowOfDays = (days) => days.map(getPrintableDay).join("");
/**
* @param {number[][]} month
* @returns {string}
*/
const getPrintableRowsOfDays = (month) => month.map(getPrintableRowOfDays).join("\n");
/**
* Print a table to show all days of a specific month.
*
* @example: Farvardin, 1397
* printMonthMatrix(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
*
* @param {number} year
* @param {number} month
* @returns {boolean} true if everything goes fine.
*/
function printMonthMatrix(year, month) {
log("J P Ch Se D Y S\n"
+ "-------------------------------------\n"
+ getPrintableRowsOfDays(monthMatrix(year, month))
);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment