-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
Exercises/1-callback.js
Outdated
callback(new Error('obj needed')); | ||
return; | ||
} | ||
for (const key in obj) { |
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.
Exercises/3-wrapper.js
Outdated
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()) { |
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.
Use intermediate variables
Exercises/3-wrapper.js
Outdated
throw new TypeError('Types are different'); | ||
} | ||
} | ||
return fn(...arr); |
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.
Check result type
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.
Last argument is a result type.
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.
Check result type after calling fn
Please rebase on master to activate CI |
Exercises/3-wrapper.js
Outdated
throw new TypeError('Types are different'); | ||
} | ||
} | ||
return fn(...arr); |
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.
Check result type after calling fn
Exercises/3-wrapper.js
Outdated
if (argType !== neededArgType) { | ||
throw new TypeError('Types are different'); | ||
} | ||
if (resultType !== neededReType) { |
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.
Why do you check result types in loop?
'use strict';
const contract = (fn, ...types) => (...arr) => {
for (let i = 0; i < types.length - 1; i++) {
const argType = typeof arr[i];
const neededArgType = types[i].name.toLowerCase();
if (argType !== neededArgType) {
throw new TypeError('Types are different');
}
}
const neededReType = types[types.length - 1].name.toLowerCase();
const result = fn(...arr);
if (typeof result !== neededReType) {
throw new TypeError('Types are different');
}
return result;
};
module.exports = { contract };
Is it correct now?
…On Mon, 16 Dec 2019 at 21:28, Timur Shemsedinov ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In Exercises/3-wrapper.js
<#4 (comment)>
:
> @@ -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);
Check result type after calling fn
------------------------------
In Exercises/3-wrapper.js
<#4 (comment)>
:
> @@ -1,5 +1,21 @@
'use strict';
-const contract = (fn, ...types) => null;
+const contract = (fn, ...types) => (...arr) => {
+ const resultType = typeof fn(...arr);
+ const neededReType = types[types.length - 1].name.toLowerCase();
+ for (let i = 0; i < types.length - 1; i++) {
+ const argType = typeof arr[i];
+ const neededArgType = types[i].name.toLowerCase();
+ if (argType !== neededArgType) {
+ throw new TypeError('Types are different');
+ }
+ if (resultType !== neededReType) {
Why do you check result types in loop?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4?email_source=notifications&email_token=AMXNJKMGX2D4ZWJAGXUE6R3QY7JFFA5CNFSM4J3DL4S2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCPLBF3Y#pullrequestreview-332796655>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMXNJKKZDZXCRQH47WYLZRDQY7JFFANCNFSM4J3DL4SQ>
.
|
Please don't send changes in email, commit it directly to git because I need to see diff |
No description provided.