10 lines
240 B
JavaScript
10 lines
240 B
JavaScript
function power_of_2(n) {
|
|
if (typeof n !== 'number')
|
|
return 'Not a number';
|
|
|
|
return n && (n & (n - 1)) === 0;
|
|
}
|
|
|
|
console.log(power_of_2(16));
|
|
console.log(power_of_2(18));
|
|
console.log(power_of_2(256));
|