Skip to content

Commit 27d6abf

Browse files
committed
refactoring
1 parent 6614f10 commit 27d6abf

File tree

11 files changed

+33
-31
lines changed

11 files changed

+33
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class FileElement extends FileSystemElement {
5757
// Print this element with the "upperPath".
5858
print(upperPath) {
5959
// ˅
60-
console.log(upperPath + '/' + this.toString());
60+
console.log(`${upperPath}/${this.toString()}`);
6161
// ˄
6262
}
6363

behavioral-patterns/chain-of-responsibility/supporter.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Supporter {
2828
if (this.canHandle(trouble)) {
2929
this.supported(trouble);
3030
}
31-
else if (this.next != null) {
31+
else if (this.next !== null) {
3232
this.next.support(trouble);
3333
}
3434
else {

behavioral-patterns/command/app-main.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class AppMain {
2727

2828
constructor() {
2929
// ˅
30+
this.isDragging = false;
3031
this.canvas = document.getElementById(`canvas`);
3132
this.undoButton = document.getElementById(`undoButton`)
3233
this.clearButton = document.getElementById(`clearButton`)
@@ -54,9 +55,9 @@ export class AppMain {
5455
if(this.isDragging){
5556
const paintingPosX = event.clientX - this.canvas.getBoundingClientRect().left;
5657
const paintingPosY = event.clientY - this.canvas.getBoundingClientRect().top ;
57-
const paintingCommand = new PaintingCommand(this.paintingCanvas, paintingPosX, paintingPosY);
58-
this.history.add(paintingCommand);
59-
paintingCommand.execute();
58+
const command = new PaintingCommand(this.paintingCanvas, paintingPosX, paintingPosY);
59+
this.history.add(command);
60+
command.execute();
6061
}
6162
// ˄
6263
}

behavioral-patterns/command/history-command.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class HistoryCommand extends Command {
3939
// Delete the last command
4040
undo() {
4141
// ˅
42-
if (this.pastCommands.length != 0) {
42+
if (this.pastCommands.length !== 0) {
4343
this.pastCommands.pop();
4444
}
4545
// ˄

behavioral-patterns/interpreter/command-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class CommandList extends Node {
2323
parse(context) {
2424
// ˅
2525
while (true) {
26-
if (context.getToken() == null) {
26+
if (context.getToken() === null) {
2727
throw new Error(`Missing "end"`);
2828
}
2929
else if (context.getToken() === `end`) {

behavioral-patterns/visitor/directory-element.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export class DirectoryElement extends FileSystemElement {
3939

4040
get size() {
4141
// ˅
42-
let value = 0;
42+
let size = 0;
4343
for (let element of this.elements) {
44-
value += element.size;
44+
size += element.size;
4545
}
46-
return value;
46+
return size;
4747
// ˄
4848
}
4949

creational-patterns/abstract-factory/main.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,24 @@ const readline = rl.createInterface({
1717
});
1818

1919
readline.question(``, (data) => {
20-
let input = Number(data);
20+
const input = Number(data);
2121
readline.close();
2222
if (isNaN(input)) {
2323
console.log(`Unexpected value.`);
2424
process.exit(1);
2525
}
2626

2727
let factory = null;
28-
if (input == 1) {
29-
factory = new ListFactory();
30-
}
31-
else if (input == 2) {
32-
factory = new TableFactory();
33-
}
34-
else {
35-
console.log(`The value is not 1 or 2.`);
36-
process.exit(1);
28+
switch (input) {
29+
case 1:
30+
factory = new ListFactory();
31+
break;
32+
case 2:
33+
factory = new TableFactory();
34+
break;
35+
default:
36+
console.log(`The value is not 1 or 2.`);
37+
process.exit(1);
3738
}
3839

3940
const washingtonPost = factory.createLink(`The Washington Post`, `https://www.washingtonpost.com/`);

creational-patterns/builder/main.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ const readline = rl.createInterface({
1818
});
1919

2020
readline.question(``, (data) => {
21-
let input = data;
21+
const input = data;
2222
readline.close();
2323

24-
if (input == `plain`) {
24+
if (input === `plain`) {
2525
const plainTextBuilder = new PlainTextBuilder();
2626
const directory = new Director(plainTextBuilder);
2727
directory.build();
2828

2929
const content = plainTextBuilder.getContent();
3030
console.log(content);
3131
}
32-
else if (input == `html`) {
32+
else if (input === `html`) {
3333
const htmlBuilder = new HTMLBuilder();
3434
const directory = new Director(htmlBuilder);
3535
directory.build();

structural-patterns/composite/directory-element.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class DirectoryElement extends FileSystemElement {
3131
get size() {
3232
// ˅
3333
let size = 0;
34-
for (let i = 0; i < this.elements.length; i++) {
35-
size += this.elements[i].size;
34+
for (let element of this.elements) {
35+
size += element.size;
3636
}
3737
return size;
3838
// ˄
@@ -42,8 +42,8 @@ export class DirectoryElement extends FileSystemElement {
4242
print(upperPath) {
4343
// ˅
4444
console.log(`${upperPath}/${this.toString()}`);
45-
for (let i = 0; i < this.elements.length; i++) {
46-
this.elements[i].print(`${upperPath}/${this.name}`);
45+
for (let element of this.elements) {
46+
element.print(`${upperPath}/${this.name}`);
4747
}
4848
// ˄
4949
}

structural-patterns/decorator/side-frame.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class SideFrame extends Frame {
1717
// ˅
1818
super(display);
1919

20-
if (frameChar.length != 1) {
20+
if (frameChar.length !== 1) {
2121
console.log(`Only one character is allowed in a side frame.`);
2222
process.exit(1);
2323
}

0 commit comments

Comments
 (0)