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 fizzBuzz(n) { | |
| const result = []; | |
| for (let i = 1; i <= n; i++) { | |
| if (i % 3 === 0 && i % 5 === 0) { | |
| result.push("FizzBuzz"); | |
| } else if (i % 3 === 0) { | |
| result.push("Fizz"); | |
| } else if (i % 5 === 0) { | |
| result.push("Buzz"); |
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 calculateTotal(cart) { | |
| let total = 0; | |
| for (let i = 0; i < cart.length; i++) { | |
| const price = Number(cart[i].price); | |
| const quantity = Number(cart[i].quantity); | |
| total += price * quantity; | |
| } | |
| return total; | |
| } |
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 titleCase(sentence) { | |
| const words = sentence.split(' '); | |
| for (let i = 0; i < words.length; i++) { | |
| if (words[i]) { | |
| words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase(); | |
| } | |
| } | |
| return words.join(' '); | |
| } |
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 isPalindrome(str) { | |
| const cleanedStr = str.toLowerCase().replace(/[^a-z0-9]/g, ""); | |
| const reversedStr = cleanedStr.split("").reverse().join(""); | |
| return cleanedStr === reversedStr; | |
| } | |
| module.exports = { isPalindrome }; |
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) { | |
| const bmi = weight / (height * height); | |
| if (bmi < 18.5) { | |
| return "Underweight"; | |
| } else if (bmi >= 18.5 && bmi < 24.9) { | |
| return "Normal weight"; | |
| } else if (bmi >= 25 && bmi < 29.9) { | |
| return "Overweight"; | |
| } else { |