Skip to content

Instantly share code, notes, and snippets.

@AnandIsCoding
AnandIsCoding / 01_cbf-01_isPowerOfTwo.js
Last active March 29, 2025 21:05 — forked from tapash-almabetter/00_End Course Capstone Project.md
End Course Capstone Project - Module 2
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)
@AnandIsCoding
AnandIsCoding / 01_calculateBMI.js
Last active January 6, 2025 08:36 — forked from tapash-almabetter/00_End Course Capstone Project.md
End Course Capstone Project - Module 1
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) {