re: Project Euler #4 - Largest Palindrome Product VIEW POST

FULL DISCUSSION
 

My typescript solution:

function reverseInteger(n: number): number {
  return Number(String(n).split('').reverse().join(''));
}

function isPalindrome(num: number): boolean {
  if (num === reverseInteger(num)) {
    return true;
  }
  return false;
}

// I had this in separate files sorry if its confusing X)
import { max } from 'mathjs';

let number = 0;
let a = 999;

const palindromes: number[] = [];

while (a > 1) {
  for (let i = 2; i <= 999; i += 1) {
    number = a * i;
    if (isPalindrome(number)) {
      palindromes.push(number);
    }
  }
  a -= 1;
}
console.log(`Max palindrome ${max(...palindromes)}`);
 
if (condition) {
  return true;
}
return false;

Please don't do this 😕 It's verbose for no reason. You can accomplish the same with just return condition;.

 

cool! yes so much simple

function isPalindrome(num: number): boolean {
  return num === reverseInteger(num);
}

thanks!

code of conduct - report abuse