Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Bit-Manipulation/NextPowerOfTwo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
*
* This script will find next power of two
* of given number.
* More about it:
* https://www.techiedelight.com/round-next-highest-power-2/
*
*/

export const nextPowerOfTwo = (n) => {
if (n > 0 && (n & (n - 1)) === 0) return n
let result = 1
while (n > 0) {
result = result << 1
n = n >> 1
}
return result
}
2 changes: 1 addition & 1 deletion Bit-Manipulation/test/IsPowerOfTwo.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IsPowerOfTwo} from '../IsPowerOfTwo'
import { IsPowerOfTwo } from '../IsPowerOfTwo'

test('Check if 0 is a power of 2 or not:', () => {
const res = IsPowerOfTwo(0)
Expand Down
18 changes: 18 additions & 0 deletions Bit-Manipulation/test/NextPowerOfTwo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { nextPowerOfTwo } from '../NextPowerOfTwo'

describe('NextPowerOfTwo', () => {
it.each`
input | result
${0} | ${1}
${1} | ${1}
${2} | ${2}
${3} | ${4}
${5} | ${8}
${125} | ${128}
${1024} | ${1024}
${10000} | ${16384}
`('returns $result when is given $input', ({ input, result }) => {
const res = nextPowerOfTwo(input)
expect(res).toBe(result)
})
})
5 changes: 2 additions & 3 deletions Conversions/TemperatureConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ const fahrenheitToRankine = (fahrenheit) => {
const kelvinToCelsius = (kelvin) => {
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
// Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
return Math.round((kelvin) - 273.15)

return Math.round((kelvin) - 273.15)
}

const kelvinToFahrenheit = (kelvin) => {
Expand All @@ -53,7 +52,7 @@ const kelvinToFahrenheit = (kelvin) => {
const kelvinToRankine = (kelvin) => {
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
// Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale
return Math.round(( (kelvin) * 9 / 5))
return Math.round(((kelvin) * 9 / 5))
}

const rankineToCelsius = (rankine) => {
Expand Down