mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-20 02:23:24 +08:00
16 lines
218 B
JavaScript
16 lines
218 B
JavaScript
/**
|
|
*
|
|
* This script will find next power of two
|
|
* of given number.
|
|
*
|
|
*/
|
|
|
|
export const nextPowerOfTwo = (n) => {
|
|
let result = 1
|
|
while (n > 0) {
|
|
result = result << 1
|
|
n = n >> 1
|
|
}
|
|
return result
|
|
}
|