4

I don't understand what >>= means (I thought greater than or equal to was >=) also what is: (times & 1) from below.

function repeat (string, times) {
var result = ''
while (times > 0) {
if (times & 1) result += string
times >>= 1
string += string
}
 return result
}
Evorlor
  • 6,158
  • 16
  • 60
  • 122
Jeff Collins
  • 65
  • 1
  • 4

1 Answers1

5

>>= is a right-shift-and-assign see. >>= 1 is simply integer division by 2.

& is a Bitwise AND see. time & 1 is simply checking if it is odd.

For more in-depth guide on all javascript operators, see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators

Dinesh
  • 4,039
  • 4
  • 34
  • 68