Algorithm question

That’s funny that your teacher chose a less efficient method.

I think

while (int % 60 !==1) {
  int +=7
}
console.log(int)

would be an improvement - few computations. The modulus is an especially time consuming operation (relative to others). I would want to limit it to one if I could.

And of course:

let int = 60 + 1

while (int % 7 !== 0 ) {
  int +=60
}

gets there faster.

I’m not saying this is better, but this is another approach:

let sevenMultiple = 7
let otherMultiple = 60

while (sevenMultiple !== otherMultiple + 1) {
  if (sevenMultiple < otherMultiple + 1) {
    sevenMultiple += 7
  } else {
    otherMultiple += 60
  }
}
console.log(sevenMultiple)

inching each multiple along to find the first place where the intersect.