SHARE
TWEET

Untitled

a guest Nov 20th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. calendarMatrix() {
  2.                 function range(start, end) {
  3.                     let ret = [];
  4.                     for (let i = start; i < end; i++) {
  5.                         ret.push(i);
  6.                     }
  7.                     return ret;
  8.                 }
  9.  
  10.                 function nulls(count) {
  11.                     return (new Array(count)).fill(null);
  12.                 }
  13.  
  14.                 function actualWeekday(day) {
  15.                     return (day + 6) % 7;
  16.                 }
  17.  
  18.                 const startDay = new Date(this.year, this.month, 1);
  19.                 const endDay = new Date(this.year, this.month + 1, 0);
  20.  
  21.                 const calendarPool = [
  22.                     ...nulls(actualWeekday(startDay.getDay())),
  23.                     ...range(startDay.getDate(), endDay.getDate() + 1),
  24.                     ...nulls(6 - actualWeekday(endDay.getDay())),
  25.                 ];
  26.  
  27.                 console.log(calendarPool);
  28.  
  29.                 let calendarMatrix = [];
  30.                 for (let step = 0; step < Math.floor(calendarPool.length / 7); step++) {
  31.                     calendarMatrix.push(calendarPool.slice(step * 7, (step + 1) * 7))
  32.                 }
  33.                 return calendarMatrix;
  34.             }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top