-
Notifications
You must be signed in to change notification settings - Fork 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
Add flakey Date.prototype.getDay and Object.keys #3
base: main
Are you sure you want to change the base?
Conversation
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.
Hi! it took me a while to review your PR due to the summer but thank you so much!
Added a few comments- your ideas are fantastic btw hahahha.
const clonedNow = Date.now | ||
const clonedGetDay = Date.prototype.getDate |
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.
const clonedGetDay = Date.prototype.getDate | |
const clonedGetDay = Date.prototype.getDay |
let incorrectDay = clonedMathFloor(clonedMathRandom() * 7) | ||
|
||
// Math.random() could theoretically return 1, which would make incorrectDay 7 | ||
// 7 is not a valid day of the week, so we need to change it to 6 | ||
if (incorrectDay === 7) { | ||
incorrectDay = 6 | ||
} | ||
|
||
return incorrectDay |
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.
let incorrectDay = clonedMathFloor(clonedMathRandom() * 7) | |
// Math.random() could theoretically return 1, which would make incorrectDay 7 | |
// 7 is not a valid day of the week, so we need to change it to 6 | |
if (incorrectDay === 7) { | |
incorrectDay = 6 | |
} | |
return incorrectDay | |
return Math.min(clonedMathFloor(clonedMathRandom() * 7), 6) |
Object.keys = function (obj: object): string[] { | ||
let keys = clonedKeys.call(this, obj); | ||
|
||
if (clonedMathRandom() < 0.5) { |
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.
let's shuffle based on generatePercentChanceToFlake.
This is so when someone makes PERCENT_CHANCE_OF_SUCCESS
100, they can completely disable all possible weirdness
I
hatelove JS! <3Therefore, I wanted to add more flakeyness and support you on the great journey to make JS more
flakeyawesome.See below my implementation for Date.prototype.getDay and Object.keys.
I espacially love the Object.keys implementation, it adds some real spice to JS. The shuffling is tricky as you could rely on it but I love that, under very rare circumstances (2% of flakey-cases), you actually get "flaked"!
Have a really great day! :)