This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { isPowerOfTwo }; | |
| function isPowerOfTwo(n) { | |
| if (n <= 0) return false; // Handle non-positive numbers | |
| return (n & (n - 1)) === 0; // Check if it's a power of two | |
| } | |
| // Test Cases | |
| console.log(isPowerOfTwo(1)) // true (2^0) | |
| console.log(isPowerOfTwo(3)) // false (not a power of 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function calculateBMI(weight, height) { | |
| // Write your code here | |
| if(isNaN(weight) || isNaN(height) || weight<=0 || height <=0 || typeof weight === "undefined" || typeof height === "undefined"){ | |
| return 'Invalid input' | |
| } | |
| // Even if the inputs are strings (e.g., "70kg", "1.75m"), parseFloat will convert valid numeric portions into numbers. | |
| weight = parseFloat(weight) | |
| height = parseFloat(height) | |
| const bmi = weight / (height * height); | |
| if (bmi < 18.5) { |