Skip to content

Commit 408ba7d

Browse files
committed
make sure a solution always shows up, use "demo" if exists
1 parent 360be9e commit 408ba7d

File tree

25 files changed

+59
-95
lines changed

25 files changed

+59
-95
lines changed
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
11
Just loop over the object and `return false` immediately if there's at least one property.
2-
3-
```js
4-
function isEmpty(obj) {
5-
for (let key in obj) {
6-
return false;
7-
}
8-
return true;
9-
}
10-
```
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
``` js run
2-
3-
// before the call
4-
let menu = {
5-
width: 200,
6-
height: 300,
7-
title: "My menu"
8-
};
9-
10-
function multiplyNumeric(obj) {
11-
for (let key in obj) {
12-
if (typeof obj[key] == 'number') {
13-
obj[key] *= 2;
14-
}
15-
}
16-
}
17-
18-
alert(menu);
19-
```

1-js/04-object-basics/04-object-methods/7-calculator/solution.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
3-
```js run demo
2+
```js run demo solution
43
let calculator = {
54
sum() {
65
return this.a + this.b;
@@ -20,4 +19,3 @@ calculator.read();
2019
alert( calculator.sum() );
2120
alert( calculator.mul() );
2221
```
23-

1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The solution is to return the object itself from every call.
22

3-
```js run
3+
```js run demo
44
let ladder = {
55
step: 0,
66
up() {
@@ -28,7 +28,7 @@ ladder.up().up().down().up().down().showStep(); // 1
2828

2929
We also can write a single call per line. For long chains it's more readable:
3030

31-
```js
31+
```js
3232
ladder
3333
.up()
3434
.up()
@@ -37,4 +37,3 @@ ladder
3737
.down()
3838
.showStep(); // 1
3939
```
40-

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/solution.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
```js run demo
42
function Calculator() {
53

1-js/05-data-types/03-string/3-truncate/solution.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ The maximal length must be `maxlength`, so we need to cut it a little shorter, t
22

33
Note that there is actually a single unicode character for an ellipsis. That's not three dots.
44

5-
```js run
5+
```js run demo
66
function truncate(str, maxlength) {
7-
return (str.length > maxlength) ?
7+
return (str.length > maxlength) ?
88
str.slice(0, maxlength - 1) + '' : str;
99
}
1010
```
11-
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
```js run
2-
function extractCurrencyValue(str) {
3-
return +str.slice(1);
4-
}
5-
```

1-js/05-data-types/04-array/10-maximal-subarray/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# The slow solution
1+
# Slow solution
22

33
We can calculate all possible subsums.
44

@@ -67,7 +67,7 @@ Let's walk the array and keep the current partial sum of elements in the variabl
6767

6868
If the description is too vague, please see the code, it's short enough:
6969

70-
```js run
70+
```js run demo
7171
function getMaxSubSum(arr) {
7272
let maxSum = 0;
7373
let partialSum = 0;
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
function camelize(str) {
22
return str
3-
.split('-') // my-long-word -> ['my', 'long', 'word']
4-
.map(
3+
.split('-') // splits 'my-long-word' into array ['my', 'long', 'word']
4+
.map(
5+
// capitalizes first letters of all array items except the first one
6+
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word']
57
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
6-
) // ['my', 'long', 'word'] -> ['my', 'Long', 'Word']
7-
.join(''); // ['my', 'Long', 'Word'] -> myLongWord
8+
)
9+
.join(''); // joins ['my', 'Long', 'Word'] into 'myLongWord'
810
}

1-js/05-data-types/05-array-methods/11-array-unique/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Let's walk the array items:
22
- For each item we'll check if the resulting array already has that item.
33
- If it is so, then ignore, otherwise add to results.
44

5-
```js run
5+
```js run demo
66
function unique(arr) {
77
let result = [];
88

0 commit comments

Comments
 (0)