Created
May 17, 2025 16:37
-
-
Save davidystephenson/7fca7c6daae861436197e95d1096e88a to your computer and use it in GitHub Desktop.
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
// Question 1: Anonymous Function | |
// Write an anonymous function that takes two numbers as parameters and returns their sum. | |
var add = function (x, y) { | |
return x + y | |
} | |
console.log(add(10, 5)) | |
console.log("\n-------------------------------------------------\n"); | |
// 2. Write a function `isEven` that takes a number as a parameter and returns `true` if it is even, and `false` otherwise. | |
function isEven (number) { | |
var remainder = number % 2 | |
var even = remainder === 0 | |
return even | |
} | |
console.log(isEven(4)) | |
console.log(isEven(11)) | |
console.log("\n-------------------------------------------------\n"); | |
// 3. Implement a function that checks if a given number is a palindrome (e.g., 121, 1331). | |
function isPalindrome (number) { | |
console.log(number) | |
const string = String(number) | |
console.log(string) | |
const array = string.split('') | |
console.log(array) | |
array.reverse() | |
console.log(array) | |
const joined = array.join('') | |
console.log(joined) | |
return string === joined | |
} | |
console.log(isPalindrome(123)) | |
console.log(isPalindrome(54845)) | |
console.log("\n-------------------------------------------------\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment