(Translated by https://www.hiragana.jp/)
Add flakey Date.prototype.getDay and Object.keys by jensilo · Pull Request #3 · keidyz/enflake · GitHub
Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jensilo
Copy link

@jensilo jensilo commented Jul 6, 2024

I hate love JS! <3
Therefore, I wanted to add more flakeyness and support you on the great journey to make JS more flakey awesome.

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! :)

Copy link
Owner

@keidyz keidyz left a 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const clonedGetDay = Date.prototype.getDate
const clonedGetDay = Date.prototype.getDay

Comment on lines +16 to +24
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants