ok
This commit is contained in:
parent
9064e35f3f
commit
4c531b5ae7
371 changed files with 338 additions and 316 deletions
|
@ -0,0 +1,7 @@
|
|||
function isEmpty(obj) {
|
||||
for (let key in obj) {
|
||||
// if the loop has started, there is a prorty
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
11
1-js/4-object-basics/01-object/3-is-empty/_js.view/test.js
Normal file
11
1-js/4-object-basics/01-object/3-is-empty/_js.view/test.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
describe("isEmpty", function() {
|
||||
it("returns true for an empty object", function() {
|
||||
assert.isTrue(isEmpty({}));
|
||||
});
|
||||
|
||||
it("returns false if a property exists", function() {
|
||||
assert.isFalse(isEmpty({
|
||||
anything: false
|
||||
}));
|
||||
});
|
||||
});
|
11
1-js/4-object-basics/01-object/3-is-empty/solution.md
Normal file
11
1-js/4-object-basics/01-object/3-is-empty/solution.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
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;
|
||||
}
|
||||
```
|
||||
|
20
1-js/4-object-basics/01-object/3-is-empty/task.md
Normal file
20
1-js/4-object-basics/01-object/3-is-empty/task.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
importance: 5
|
||||
|
||||
---
|
||||
|
||||
# Check for emptiness
|
||||
|
||||
Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.
|
||||
|
||||
Should work like that:
|
||||
|
||||
```js
|
||||
let schedule = {};
|
||||
|
||||
alert( isEmpty(schedule) ); // true
|
||||
|
||||
schedule["8:30"] = "get up";
|
||||
|
||||
alert( isEmpty(schedule) ); // false
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue