Skip to content

Instantly share code, notes, and snippets.

@erhanyasar
Created June 16, 2023 16:25
Show Gist options
  • Save erhanyasar/4cb6854efce6b4d8f52c807a6d3f4f9a to your computer and use it in GitHub Desktop.
Save erhanyasar/4cb6854efce6b4d8f52c807a6d3f4f9a to your computer and use it in GitHub Desktop.
let numbersArr = [4, 6, 7, 9, 12];
function findSecondBiggestNumber(numbers) {
numbers.sort((a, b) => a - b);
return numbers[numbers.length - 2];
}
// console.log(findSecondBiggestNumber(numbersArr));
let strForReverse = "Erhan";
function reverseGivenString(str) {
return str.toLowerCase().split("").reverse().join("");
}
// console.log(reverseGivenString(strForReverse));
let strForPalindrome = "Xox";
function isPalindrome(str) {
if (str.toLowerCase() === reverseGivenString(str)) return true;
else return false;
}
// console.log(isPalindrome(strForPalindrome));
let inputForPerfectNr = 6;
function isPerfectNumber(number) {
let positiveDivisors = [],
sumOfDivisors = 0;
let numbersArr = new Array(number - 1)
.fill(0)
.map((element, index) => index + 1);
numbersArr.forEach((nr) => {
if (number % nr === 0) positiveDivisors.push(nr);
});
positiveDivisors.forEach((divisor) => (sumOfDivisors += divisor));
if (sumOfDivisors === number) return true;
else return false;
}
console.log(isPerfectNumber(inputForPerfectNr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment