Skip to content

Commit f98f6e2

Browse files
committed
feat: adds /jarededge to correct directory
1 parent 623f0bb commit f98f6e2

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

lesson_04/jarededge/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Explanation
2+
3+
I know we were instruected to only implement 2 languages but I decided to do 3 to practice writing in these languages as much as I could. Each version of the isPrime function follows the same logical structure, broken down into small helper functions for clarity and maintainability. The logic checks if a number is less than or equal to 1, whether it's 2 or 3, if it's divisible by 2 or 3, and finally uses the 6k ± 1 optimization to check for other factors efficiently.
4+
5+
## Differences for programs
6+
7+
Function Declarations & Syntax:
8+
9+
- Python uses def with colons and indentation.
10+
11+
- JavaScript and TypeScript use function and curly braces.
12+
13+
- TypeScript adds type annotations (e.g., n: number, : boolean).
14+
15+
## Type Safety:
16+
git checkout -b <new branch>
17+
- Python is dynamically typed but can include type hints.
18+
19+
- JavaScript is fully dynamic and prone to runtime type errors.
20+
21+
- TypeScript offers compile-time type checking for more robust code.
22+
23+
##Booleans & Print Statements:
24+
25+
- Python uses True/False and print()
26+
27+
- JS/TS use true/false and console.log() (uses capitol letters)
28+
29+
## Refactoring Practice:
30+
31+
- All three versions refactor logic into smaller single-responsibility functions
32+
33+
- This improves readability and testability
34+
35+
Tooling Differences:
36+
37+
- TypeScript requires a compiler (tsc) to convert code into JavaScript before execution
38+
39+
- Python and JavaScript can run directly via interpreters (e.g., python, node)
40+
41+
42+
## Differences for tests
43+
44+
- Ts files need to be compiled into .js files in order to be ran. This could be done
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export class ExpressionCalculator {
2+
/** Returns a calculation involving a, b, c, d, and e */
3+
calculate(a: number, b: number, c: number, d: number, e: number): number {
4+
// Implement your code here to return the correct value.
5+
const sum = c + d;
6+
7+
const denominator = this.pow(sum, e);
8+
9+
const numerator = a * b;
10+
11+
return numerator / denominator;
12+
}
13+
14+
pow(base: number, exponent: number): number {
15+
return Math.pow(base, exponent);
16+
}
17+
}

lesson_06/jarededge/streatch.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```ts
2+
export function isValidAlphaAbbreviation(word: string, abbr: string): boolean {
3+
let i = 0;
4+
let j = 0;
5+
6+
while (j < abbr.length) {
7+
const ch = abbr[j];
8+
9+
if (ch >= "0" && ch <= "9") {
10+
if (ch === "0") return false;
11+
12+
let num = 0;
13+
while (j < abbr.length && abbr[j] >= "0" && abbr[j] <= "9") {
14+
num = num * 10 + (abbr[j].charCodeAt(0) - "0".charCodeAt(0));
15+
j++;
16+
}
17+
18+
i += num;
19+
if (i > word.length) return false;
20+
} else {
21+
if (i >= word.length || word[i] !== ch) {
22+
return false;
23+
}
24+
i++;
25+
j++;
26+
}
27+
}
28+
29+
return i === word.length;
30+
}
31+
```

0 commit comments

Comments
 (0)