0

I've got a small problem with calculating eastern. The code below gives out 35 in Java which is correct but 34 in javascript in the browser when using year=2021. It is reproducible by using double in Java for the two numbers which are surrounded by parseInt. I already tried parsint and Math.trunc.

function calcEastern(year) {
  let k = Math.trunc(year / parseInt(100, 10));
  let m = Math.trunc(15 + (3 * k + 3) / 4 - (8 * k + 13) / 25);
  let s = Math.trunc(2 - (3 * k + 3) / 4);
  let a = Math.trunc(year % 19);
  let d = Math.trunc((19 * a + m) % 30);
  let r = Math.trunc((d + a / 11) / 29);
  let og = Math.trunc(21 + d - r);
  let sz = Math.trunc(7 - (year + year / parseInt(4, 10) + s) % 7);
  let oe = Math.trunc(7 - (og - sz) % 7);
  console.log(og + oe);
  return og + oe;
}


calcEastern(2020)
calcEastern(2021)

For those who are interested, this calculation gives out the day of Easter Sunday in a march format. This year it would be the 35th of march so 4th of April.

Not A Bot
  • 2,474
  • 2
  • 16
  • 33

2 Answers2

0

At, let m = Math.trunc(15 + (3 k + 3) / 4 - (8 k + 13) / 25); the compiler will give "Uncaught SyntaxError: Unexpected identifier" in javaScript.

Rupesh Pathak
  • 11
  • 1
  • 5
0

Ok the answer is to use Math.floor which is an oversight by me since m is negative trunc would cut the last digits and floor would round them. The accepted answer of this shows it perfectly Math.floor VS Math.trunc JavaScript.