Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
My work #4
Open
My work #4
Conversation
Exercises/1-callback.js
Outdated
| callback(new Error('obj needed')); | ||
| return; | ||
| } | ||
| for (const key in obj) { |
tshemsedinov
Dec 16, 2019
Member
This will iterate all object keys plus inherited keys from prototype chain.
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()) { |
tshemsedinov
Dec 16, 2019
Member
Use intermediate variables
Use intermediate variables
Exercises/3-wrapper.js
Outdated
| throw new TypeError('Types are different'); | ||
| } | ||
| } | ||
| return fn(...arr); |
tshemsedinov
Dec 16, 2019
Member
Check result type
Check result type
tshemsedinov
Dec 16, 2019
Member
Last argument is a result type.
Last argument is a result type.
tshemsedinov
Dec 16, 2019
Member
Check result type after calling fn
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); |
tshemsedinov
Dec 16, 2019
Member
Check result type after calling fn
Check result type after calling fn
Exercises/3-wrapper.js
Outdated
| if (argType !== neededArgType) { | ||
| throw new TypeError('Types are different'); | ||
| } | ||
| if (resultType !== neededReType) { |
tshemsedinov
Dec 16, 2019
Member
Why do you check result types in loop?
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
No description provided.