-
-
Notifications
You must be signed in to change notification settings - Fork 78
My work #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
My work #4
Changes from 3 commits
4fae9ce
78ef473
c2e9629
c0d9e7a
2af4528
e7fef1a
17aeeb0
f8cbfc8
6eb04e3
1fc193e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| const iterate = (obj, callback) => null; | ||
| const iterate = (obj, callback) => { | ||
| if (!obj) { | ||
| callback(new Error('obj needed')); | ||
| return; | ||
| } | ||
| for (const key in obj) { | ||
| callback(key, obj[key], obj); | ||
| } | ||
| return; | ||
| }; | ||
|
|
||
| module.exports = { iterate }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| const store = x => null; | ||
| const store = x => () => x; | ||
|
|
||
| module.exports = { store }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
| const contract = (fn, ...types) => null; | ||
| const contract = (fn, ...types) => (...arr) => { | ||
| for (let i = 1; i < types.length - 1; i++) { | ||
| if (typeof fn(...arr) !== types[i].name.toLowerCase()) { | ||
|
||
| throw new TypeError('Types are different'); | ||
| } | ||
| } | ||
| return fn(...arr); | ||
|
||
| }; | ||
|
|
||
| module.exports = { contract }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will iterate all object keys plus inherited keys from prototype chain.