0

found an incomprehensible case for myself in some examples on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

There is example:

function isPrime(element, index, array) {
  var start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1)** {
      return false;
    }
  }
  return element > 1;
}

My test input: console.log([ 8, 12, 7 ].find(isPrime))

So the qustion is why (element % start++ < 1) is true when element is 8, i checked operator precedence and increment '++' has a higher priority than '%' , ==> 8 % 3 = 1 - should be false

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Qugean
  • 9
  • 2

0 Answers0