Skip to content

Commit 1788def

Browse files
committed
Cleaning up lint errors, adjusting Makefile, queue.ts implementation
1 parent a5c504d commit 1788def

File tree

11 files changed

+2981
-8
lines changed

11 files changed

+2981
-8
lines changed

Makefile

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,51 @@
22

33
CC := gcc
44
CFLAGS := -Wall -Wextra -Werror -g
5+
6+
# Typescript
7+
TS := $(shell find . -type f -name '*.ts' ! -path './node_modules/*')
8+
JS := $(TS:.ts=.js)
9+
10+
# C
511
SRC := $(shell find . -type f -name '*.c')
612
OUT := $(SRC:.c=.out)
713

8-
.PHONY: all clean check
14+
.PHONY: all clean check ts c
915

10-
all: $(OUT)
16+
# Default build target
17+
all: c ts
18+
19+
# C Compilation
20+
c: $(OUT)
1121

1222
# Pattern rule: build file.c into file.out
1323
%.out: %.c
1424
@echo "Compiling $< -> $@"
1525
$(CC) $(CFLAGS) $< -o $@
1626

27+
# TypeScript Compilation
28+
ts: $(JS)
29+
30+
%.js: %.ts
31+
@echo "Transpiling $< -> $@"
32+
tsc $<
33+
1734
check: all
18-
@echo "Running compiled examples..."
35+
@echo "Running compiled C examples..."
1936
@for bin in $(OUT); do \
2037
echo ">> $$bin"; \
2138
./$$bin || echo "Error in $$bin"; \
2239
done
40+
@echo "Running compiled TypeScript examples..."
41+
@for js in $(JS); do \
42+
echo ">> $$js"; \
43+
node $$js || echo "Error in $$js"; \
44+
done
2345

2446
clean:
2547
@echo "Cleaning up compiled files..."
26-
find . -type f \( -name '*.out' -o -name '*.exe' -o -name '*.o' \) -exec rm -f {} +
48+
find . -type f \( -name '*.out' -o -name '*.js' \) -exec rm -f {} +
49+
50+
lint:
51+
@echo "Linting TypeScript files..."
52+
npx eslint '**/*.ts'

algorithms/data_structures/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
- `isEmpty` - Test if queue has no elements
1010
- `Size` - Returns the size of the queue
1111

12+
- [C Queue](queue.c) - Example C Implementation of Queue
13+
- [TS Queue](queue.ts) - Example TypeScript Implementation of Queue
14+
1215
## Stacks
1316
- **LIFO** **L**ast **I**n **F**irst **O**ut - just like a stack of papers on your desk, you add and remove from the top.
1417
- Operations
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Queue
3+
* A TypeScript Class Based Queue Implementation
4+
*/
5+
6+
class Queue<T>
7+
{
8+
private items: T[] = [];
9+
10+
enqueue(item: T)
11+
{
12+
this.items.push(item);
13+
}
14+
15+
dequeue(): T | undefined
16+
{
17+
return this.items.shift();
18+
}
19+
20+
peek(): T | undefined
21+
{
22+
return this.items[0];
23+
}
24+
25+
isEmpty(): boolean
26+
{
27+
return this.items.length === 0;
28+
}
29+
30+
size(): number
31+
{
32+
return this.items.length;
33+
}
34+
}
35+
36+
// example usage
37+
38+
const q = new Queue<number>();
39+
40+
q.enqueue(10);
41+
q.enqueue(20);
42+
43+
console.log(q.dequeue()); // 10
44+
console.log(q.peek()); // 20
45+
46+
console.log(q.isEmpty()); // false
47+
console.log(q.size()); // 1

design_patterns/behavioral/observer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class AirConditionerObserver implements Observer {
125125
}
126126

127127
if (scene === "movie-night") {
128-
128+
// TODO: perform actions for movie-night scene
129+
console.log("Movie night time");
129130
}
130131
}
131132
}

design_patterns/creational/factory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ export class ConfigurableLightFactory implements LightSceneFactory {
4040
}
4141
return new RGBLightDecorator(light, this.color);
4242
}
43+
44+
createDimmingLight(): PowerControl & BrightnessControl {
45+
let dimmingLight: PowerControl & BrightnessControl = new LightBulb();
46+
for (const decorate of this.decorators) {
47+
dimmingLight = decorate(dimmingLight);
48+
}
49+
return new DimmingLightDecorator(dimmingLight);
50+
}
4351
}

design_patterns/creational/singleton.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
* central point of control for the devices.
2323
*/
2424

25-
import { SmartTV, AirConditioner } from "../class";
26-
2725
type SceneName =
2826
| "movie-night"
2927
| "good-morning"

design_patterns/creational/singleton/main.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
* main.ts
33
* Example Singleton Implementation
44
* An example of how the Singleton is used once the pattern is coded
5+
* AirConditioner and SmartTV
56
*/
67

78
import { SingletonHomeHub } from '../singleton';
89
import { SmartTVObserver } from '../../behavioral/observer';
10+
import { AirConditionerObserver } from '../../behavioral/observer';
911
import { SmartTV } from '../../class';
12+
import { AirConditioner } from '../../class';
1013

1114
const hub = SingletonHomeHub.getInstance();
1215
const tv = new SmartTVObserver();
16+
const ac = new AirConditionerObserver();
17+
18+
const smartTelly = new SmartTV("Lounge");
19+
const smartAC = new AirConditioner("Dining");
1320

1421
// Subscribe the TV to the "romantic" scene
15-
hub.subscribe("romantic", tv);
22+
hub.subscribe("party-time", tv);
23+
24+
// Subscribe the A/C to the "warm-up-buttercup" scene
25+
hub.subscribe("movie-night", ac);
26+
27+
smartTelly.home();
28+
smartAC.powerOn();

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import tseslint from "typescript-eslint";
4+
import markdown from "@eslint/markdown";
5+
import { defineConfig } from "eslint/config";
6+
7+
export default defineConfig([
8+
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } },
9+
tseslint.configs.recommended,
10+
{ files: ["**/*.md"], plugins: { markdown }, language: "markdown/gfm", extends: ["markdown/recommended"] },
11+
]);

0 commit comments

Comments
 (0)