make sure a solution always shows up, use "demo" if exists
This commit is contained in:
parent
360be9ed99
commit
408ba7d4e4
25 changed files with 59 additions and 95 deletions
|
@ -1,10 +1 @@
|
|||
Just loop over the object and `return false` immediately if there's at least one property.
|
||||
|
||||
```js
|
||||
function isEmpty(obj) {
|
||||
for (let key in obj) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
``` js run
|
||||
|
||||
// before the call
|
||||
let menu = {
|
||||
width: 200,
|
||||
height: 300,
|
||||
title: "My menu"
|
||||
};
|
||||
|
||||
function multiplyNumeric(obj) {
|
||||
for (let key in obj) {
|
||||
if (typeof obj[key] == 'number') {
|
||||
obj[key] *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
alert(menu);
|
||||
```
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
|
||||
```js run demo
|
||||
```js run demo solution
|
||||
let calculator = {
|
||||
sum() {
|
||||
return this.a + this.b;
|
||||
|
@ -20,4 +19,3 @@ calculator.read();
|
|||
alert( calculator.sum() );
|
||||
alert( calculator.mul() );
|
||||
```
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
The solution is to return the object itself from every call.
|
||||
|
||||
```js run
|
||||
```js run demo
|
||||
let ladder = {
|
||||
step: 0,
|
||||
up() {
|
||||
|
@ -28,7 +28,7 @@ ladder.up().up().down().up().down().showStep(); // 1
|
|||
|
||||
We also can write a single call per line. For long chains it's more readable:
|
||||
|
||||
```js
|
||||
```js
|
||||
ladder
|
||||
.up()
|
||||
.up()
|
||||
|
@ -37,4 +37,3 @@ ladder
|
|||
.down()
|
||||
.showStep(); // 1
|
||||
```
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
```js run demo
|
||||
function Calculator() {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue