mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-15 02:33:35 +08:00

* Fix Euler Problem 3 * Fix indentation Co-authored-by: Sutthinart Khunvadhana <sutthinart.khunvadhana@refinitiv.com>
21 lines
428 B
JavaScript
21 lines
428 B
JavaScript
// https://projecteuler.net/problem=3
|
|
const problem = 600851475143
|
|
|
|
const largestPrime = (num) => {
|
|
let newnumm = num
|
|
let largestFact = 0
|
|
let counter = 2
|
|
while (counter * counter <= newnumm) {
|
|
if (newnumm % counter === 0) {
|
|
newnumm = newnumm / counter
|
|
} else {
|
|
counter++
|
|
}
|
|
}
|
|
if (newnumm > largestFact) {
|
|
largestFact = newnumm
|
|
}
|
|
return largestFact
|
|
}
|
|
console.log(largestPrime(problem))
|