Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 02ed22e

Browse files
committed
chapter 4 reviews
1 parent f029666 commit 02ed22e

10 files changed

+45
-277
lines changed

‎src/04-stack/01-undo-feature.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// src/04-stack/01-undo-feature.js
2+
3+
const Stack = require('./stack');
4+
// import { Stack } from './stack'; // or './stack.js' if you are using ES modules
5+
6+
const undoFeature = new Stack();
7+
8+
console.log(undoFeature.isEmpty()); // true
9+
10+
undoFeature.push({action: 'typing', text: 'S'});
11+
undoFeature.push({action: 'typing', text: 't'});
12+
13+
console.log(undoFeature.peek()); // { action: 'typing', text: 't' }
14+
15+
console.log(undoFeature.size); // 2
16+
17+
undoFeature.push({action: 'typing', text: 'a'});
18+
undoFeature.push({action: 'typing', text: 'c'});
19+
undoFeature.push({action: 'typing', text: 'k'});
20+
21+
console.log(undoFeature.size); // 5
22+
console.log(undoFeature.isEmpty()); // false
23+
24+
// removing two elements from the stack
25+
undoFeature.pop();
26+
undoFeature.pop();
27+
28+
console.log(undoFeature.size); // 3
29+
console.log(undoFeature.peek()); // { action: 'typing', text: 'a' }
30+
31+
// toString
32+
console.log(undoFeature.toString());
33+
34+
// to see the output of this file use the command: node src/04-stack/01-undo-feature.js

‎src/04-stack/01-using-stack-class.js‎

Lines changed: 0 additions & 34 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

‎src/04-stack/02-using-stack-object-class.js‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎src/04-stack/02-using-stack-object-class.ts‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎src/04-stack/decimal-to-base.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ function decimalToBase(decimalNumber, base) {
1414
throw new Error('Base must be between 2 and 36');
1515
}
1616

17+
if (decimalNumber === 0) { return '0'; }
18+
19+
if (decimalNumber < 0) {
20+
throw new Error('Negative numbers are not supported');
21+
}
22+
1723
const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // Digits for base 36
1824
const remainderStack = new Stack();
1925
let baseString = '';

‎src/04-stack/decimal-to-binary.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ function decimalToBinary(decimalNumber) {
1515
return '0';
1616
}
1717

18-
while (decimalNumber > 0) { // {1}
19-
const remainder = Math.floor(decimalNumber % 2); // {2}
20-
remainderStack.push(remainder); // {3}
21-
decimalNumber = Math.floor(decimalNumber / 2); // {4}
18+
while (decimalNumber > 0) {
19+
const remainder = Math.floor(decimalNumber % 2);
20+
remainderStack.push(remainder);
21+
decimalNumber = Math.floor(decimalNumber / 2);
2222
}
2323

24-
while (!remainderStack.isEmpty()) { // {5}
24+
while (!remainderStack.isEmpty()) {
2525
binaryString += remainderStack.pop().toString();
2626
}
2727

‎src/04-stack/stack-object.js‎

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎src/04-stack/stack-object.ts‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /