Skip to content

Commit e167c46

Browse files
authored
Merge branch 'code-differently:main' into lesson_06
2 parents bdb4bb3 + 34a55a0 commit e167c46

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check Lesson 06 Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_06/expression/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Shared Lib with Node.js
25+
working-directory: ./lib/javascript/codedifferently-instructional
26+
run: npm ci
27+
28+
- name: Build Lesson 06 with Node.js
29+
working-directory: ./lesson_06/expression
30+
run: |
31+
npm ci
32+
npm run check

.github/workflows/check_push.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- "lib/**"
99
- "lesson_02/quiz/**"
1010
- "lesson_03/quiz/**"
11+
- "lesson_06/quiz/**"
12+
- "lesson_06/expression/**"
1113
jobs:
1214
build:
1315
runs-on: ubuntu-latest
@@ -71,3 +73,16 @@ jobs:
7173
npm ci
7274
npm run compile
7375
npm run lint
76+
77+
- name: Build Lesson 06 Quiz with Node.js
78+
working-directory: ./lesson_06/quiz
79+
run: |
80+
npm ci
81+
npm run compile
82+
npm run lint
83+
84+
- name: Build Lesson 06 Expression with Node.js
85+
working-directory: ./lesson_06/expression
86+
run: |
87+
npm ci
88+
npm run compile

lesson_06/expression/src/functions.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
export const FUNCTIONS: Record<string, Function> = Object.freeze({
2-
A: (a: number, b: number, c: number, d: number, e: number) =>
3-
((a + b) * c) / Math.pow(d, e),
4-
B: (a: number, b: number, c: number, d: number, e: number) =>
5-
Math.pow(a + b, c) / (d * e),
6-
C: (a: number, b: number, c: number, d: number, e: number) =>
7-
a / b + c * Math.pow(d, e),
8-
D: (a: number, b: number, c: number, d: number, e: number) =>
9-
(a * b) / Math.pow(c + d, e),
10-
E: (a: number, b: number, c: number, d: number, e: number) =>
11-
Math.pow((a + b) / c, d) * e,
12-
F: (a: number, b: number, c: number, d: number, e: number) =>
13-
(a * Math.pow(b + c, d)) / e,
14-
G: (a: number, b: number, c: number, d: number, e: number) =>
15-
((Math.pow(a, b) + c) * d) / e,
16-
});
1+
export const FUNCTIONS: Record<string, (...args: number[]) => number> =
2+
Object.freeze({
3+
A: (a: number, b: number, c: number, d: number, e: number) =>
4+
((a + b) * c) / Math.pow(d, e),
5+
B: (a: number, b: number, c: number, d: number, e: number) =>
6+
Math.pow(a + b, c) / (d * e),
7+
C: (a: number, b: number, c: number, d: number, e: number) =>
8+
a / b + c * Math.pow(d, e),
9+
D: (a: number, b: number, c: number, d: number, e: number) =>
10+
(a * b) / Math.pow(c + d, e),
11+
E: (a: number, b: number, c: number, d: number, e: number) =>
12+
Math.pow((a + b) / c, d) * e,
13+
F: (a: number, b: number, c: number, d: number, e: number) =>
14+
(a * Math.pow(b + c, d)) / e,
15+
G: (a: number, b: number, c: number, d: number, e: number) =>
16+
((Math.pow(a, b) + c) * d) / e,
17+
});

lesson_06/expression/src/lesson6.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("Lesson6Test", () => {
1717
const c = 3;
1818
const d = 4;
1919
const e = 5;
20-
const expected = FUNCTIONS[process.env.HW_VERSION!].call(
20+
const expected = FUNCTIONS[process.env.HW_VERSION || ""].call(
2121
null,
2222
...[a, b, c, d, e],
2323
);

lesson_06/expression/src/lesson6.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const rl = createInterface({
1313
});
1414

1515
const main = async () => {
16-
const testFunction = FUNCTIONS[process.env.HW_VERSION!];
16+
const testFunction = FUNCTIONS[process.env.HW_VERSION || ""];
1717
if (testFunction === undefined) {
1818
console.log("HW_VERSION version not set in config. Exiting...");
1919
process.exit(1);

lesson_06/expression/src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export const askQuestion = (
1212
});
1313
};
1414

15-
export const getFunctionBody = (f: Function) => {
16-
const fString = f.toString().split("=>").pop()!;
17-
return beautify(fString);
15+
export const getFunctionBody = (f: () => unknown) => {
16+
const fString = f.toString().split("=>").pop();
17+
return beautify(fString || "");
1818
};
1919

2020
export const printFormualaWithValues = (
@@ -34,7 +34,7 @@ export const printFormualaWithValues = (
3434
["e", String(e)],
3535
["pow", "Math.pow"],
3636
).reduce(
37-
(acc: string, param: string[]) => acc.replace(param[0]!, param[1]!),
37+
(acc: string, param: string[]) => acc.replace(param[0], param[1]),
3838
functionBody,
3939
);
4040
console.log(`\nNow computing the value of ${formula}`);

0 commit comments

Comments
 (0)