ok
This commit is contained in:
parent
9064e35f3f
commit
4c531b5ae7
371 changed files with 338 additions and 316 deletions
|
@ -0,0 +1,7 @@
|
|||
function multiplyNumeric(obj) {
|
||||
for (let key in obj) {
|
||||
if (typeof obj[key] == 'number') {
|
||||
obj[key] *= 2;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
let menu = {
|
||||
width: 200,
|
||||
height: 300,
|
||||
title: "My menu"
|
||||
};
|
||||
|
||||
|
||||
function multiplyNumeric(obj) {
|
||||
|
||||
/* your code */
|
||||
|
||||
}
|
||||
|
||||
multiplyNumeric(menu);
|
||||
|
||||
alert( "menu width=" + menu.width + " height=" + menu.height + " title=" + menu.title );
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
describe("multiplyNumeric", function() {
|
||||
it("multiplies all numeric properties by 2", function() {
|
||||
var menu = {
|
||||
width: 200,
|
||||
height: 300,
|
||||
title: "My menu"
|
||||
};
|
||||
let result = multiplyNumeric(menu);
|
||||
assert.equal(menu.width, 400);
|
||||
assert.equal(menu.height, 600);
|
||||
assert.equal(menu.title, "My menu");
|
||||
});
|
||||
|
||||
it("returns nothing", function() {
|
||||
assert.isUndefined( multiplyNumeric({}) );
|
||||
});
|
||||
|
||||
});
|
33
1-js/4-object-basics/01-object/8-multiply-numeric/task.md
Normal file
33
1-js/4-object-basics/01-object/8-multiply-numeric/task.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
importance: 3
|
||||
|
||||
---
|
||||
|
||||
# Multiply numeric properties by 2
|
||||
|
||||
Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`.
|
||||
|
||||
For instance:
|
||||
|
||||
```js
|
||||
// before the call
|
||||
let menu = {
|
||||
width: 200,
|
||||
height: 300,
|
||||
title: "My menu"
|
||||
};
|
||||
|
||||
multiplyNumeric(menu);
|
||||
|
||||
// after the call
|
||||
menu = {
|
||||
width: 400,
|
||||
height: 600,
|
||||
title: "My menu"
|
||||
};
|
||||
```
|
||||
|
||||
Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.
|
||||
|
||||
P.S. Use `typeof` to check for a number here.
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue