-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
add MinMax game theory JS #1193 commented out test case #1278
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
Conversation
Dear Maintainers please have a look when you get active :) |
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.
You have various unrelated changes in there, including bumping some dependencies.
I think now it is fine |
All conflicts have now been resolved |
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.
Consider refactoring out the class. In this example, a simple function should suffice. If you don't want to repeat some calculations, consider a simple function containing a recursive closure:
export default function solveMinMax(scores, ...) {
const height = Math.log2(scores.length)
const solve = (...) => {
...
...(solve(...), solve(...))
...
}
return solve(...)
}
Furthermore, what exactly is the merit of this? In its current form, this:
- Needs to have all scores evaluated beforehand anyways, because they must be provided in an array;
- Always recurses into both branches.
Consider implementing lazily evaluating scores. I'd suggest passing a function to get a score for a node rather than an array which needs to be fully evaluated. This can also help in making this more flexible.
test('if the number is greater or equal to 2167', () => { | ||
expect(problem44(2167)).toBe(8476206790) | ||
}) | ||
// test('if the number is greater or equal to 2167', () => { |
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 unrelated change still doesn't belong here.
import { MinMax } from '../MinMax' | ||
|
||
describe('MinMax', () => { | ||
it('should return 65 for MinMax([90, 23, 6, 33, 21, 65, 123, 34423],0,0,true)', () => { |
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 test is practically equivalent to the below test. You're also duplicating the contents in the description. Please see the TypeScript guide for writing good tests.
} | ||
} | ||
|
||
// MinMax(scores, depth, nodeindex, ismax) |
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 outcommented code ought to be removed.
// >>> minimax(0, 0, True, scores, this.height) | ||
// 12 | ||
|
||
class MinMax { |
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 not prefix this with export
(perhaps even export default
) rather than export
ing below?
// 12 | ||
|
||
class MinMax { | ||
constructor (scores, depth, nodeIndex, isMax) { |
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 constructor is completely superfluous - you're passing all these as arguments to solve
later on. I'm questioning whether this should be a class at all - IMO it should just be a single solve
function that checks it parameters and recurses.
) | ||
} | ||
|
||
get_ans () { |
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.
Not in lowerCamelCase
} | ||
|
||
get_ans () { | ||
this.answer = this.solve( |
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.
Storing the answer in the class is dirty IMO; why not just return
it?
this.answer = -1 | ||
} | ||
|
||
solve (depth, nodeIndex, isMax, scores, height) { |
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.
You don't have to pass all of these as parameters - you already have them as instance variables.
* | ||
*/ | ||
|
||
// nodeIndex is index of current node in scores[]. |
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 comment is messy. There are no Python-like doc comments in this repo.
@@ -0,0 +1,86 @@ | |||
/* | |||
* | |||
* Min Max problem |
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.
Please make this a proper JSDoc comment.
I think I can't code :( |
Don't worry, your code seems to be a correct port of the code found on Geeks for Geeks. It's just that the Geeks for Geeks code is poorly structured (IMO). |
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.