Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/project-euler/problem-3-largest-prime-factor.english.md
Kristofer Koishigawa 6cfd0fc503 fix: improve Project Euler descriptions, challenge seeds, and test cases (#38016)
* fix: improve Project Euler descriptions and test case

Improve formatting of Project Euler test descriptions. Also add poker hands array and new test case for problem 54

* feat: add typeof tests and gave functions proper names for first 100 challenges

* fix: continue fixing test descriptions and adding "before test" sections

* fix: address review comments

* fix: adjust grids in 18 and 67 and fix some text that reference files rather than the given arrays

* fix: implement bug fixes and improvements from review

* fix: remove console.log statements from seed and solution
2020-02-28 06:39:47 -06:00

84 lines
1.8 KiB
Markdown

---
id: 5900f36f1000cf542c50fe82
challengeType: 5
title: 'Problem 3: Largest prime factor'
forumTopicId: 301952
---
## Description
<section id='description'>
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the given `number`?
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>largestPrimeFactor(2)</code> should return a number.
testString: assert(typeof largestPrimeFactor(2) === 'number');
- text: <code>largestPrimeFactor(2)</code> should return 2.
testString: assert.strictEqual(largestPrimeFactor(2), 2);
- text: <code>largestPrimeFactor(3)</code> should return 3.
testString: assert.strictEqual(largestPrimeFactor(3), 3);
- text: <code>largestPrimeFactor(5)</code> should return 5.
testString: assert.strictEqual(largestPrimeFactor(5), 5);
- text: <code>largestPrimeFactor(7)</code> should return 7.
testString: assert.strictEqual(largestPrimeFactor(7), 7);
- text: <code>largestPrimeFactor(13195)</code> should return 29.
testString: assert.strictEqual(largestPrimeFactor(13195), 29);
- text: <code>largestPrimeFactor(600851475143)</code> should return 6857.
testString: assert.strictEqual(largestPrimeFactor(600851475143), 6857);
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function largestPrimeFactor(number) {
// Good luck!
return true;
}
largestPrimeFactor(13195);
```
</div>
</section>
## Solution
<section id='solution'>
```js
const largestPrimeFactor = (number)=>{
let largestFactor = number;
for(let i = 2;i<largestFactor;i++){
if(!(largestFactor%i)){
largestFactor = largestFactor/i;
largestPrimeFactor(largestFactor);
}
}
return largestFactor;
}
```
</section>