Skip to content

Commit 783f8d6

Browse files
committed
chore: made revisions to README file
1 parent d7e4caf commit 783f8d6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lesson_04/nicolejackson/README

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Prime Number Functions: TypeScript vs JavaScript
2+
3+
```ts
4+
function checkPrime(num) {
5+
if (num < 2) return false;
6+
7+
for (let i = 2; i <= Math.sqrt(num); i++) {
8+
if (num % i === 0) return false;
9+
}
10+
11+
return true;
12+
}
13+
14+
function isPrime(num: number): boolean {
15+
if (num < 2) return false;
16+
17+
for (let i = 2; i <= Math.floor(Math.sqrt(num)); i++) {
18+
if (num % i === 0) return false;
19+
}
20+
21+
return true;
22+
}
23+
24+
for (let i = 2; i <= 100; i++) {
25+
console.log(`${i} is prime? ${isPrime(i)}`);
26+
}
27+
# Prime Number Functions: TypeScript vs JavaScript
28+
Above is an example of two programming languages—TypeScript and JavaScript—written to determine the primality of a number.
29+
30+
## Similarities
31+
Both the TypeScript and JavaScript implementations determine whether a number is prime. They work in the same way:by taking a single numeric input, checking divisibility only up to the square root, and then returning `true` if no divisors are found or `false` otherwise. This approach does away with unnecessary calculations and ensures efficiency. The core logic and performance of both functions are identical, making them equally effective at verifying prime numbers.
32+
33+
## Differences
34+
One way that they are different is the function names: `checkPrime` in JavaScript and `isPrime` in TypeScript.

0 commit comments

Comments
 (0)