Skip to content

Instantly share code, notes, and snippets.

@elzup
Created March 31, 2019 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elzup/79e5b09359db9ee566dd9ac7a8fde1cb to your computer and use it in GitHub Desktop.
Save elzup/79e5b09359db9ee566dd9ac7a8fde1cb to your computer and use it in GitHub Desktop.
Does month have 31days
const has31 = month => Boolean((month & 1) ^ ((month >> 3) & 1))
test('1-12', () => {
expect(has31(1)).toMatchInlineSnapshot(`true`)
expect(has31(2)).toMatchInlineSnapshot(`false`)
expect(has31(3)).toMatchInlineSnapshot(`true`)
expect(has31(4)).toMatchInlineSnapshot(`false`)
expect(has31(5)).toMatchInlineSnapshot(`true`)
expect(has31(6)).toMatchInlineSnapshot(`false`)
expect(has31(7)).toMatchInlineSnapshot(`true`)
expect(has31(8)).toMatchInlineSnapshot(`true`)
expect(has31(9)).toMatchInlineSnapshot(`false`)
expect(has31(10)).toMatchInlineSnapshot(`true`)
expect(has31(11)).toMatchInlineSnapshot(`false`)
expect(has31(12)).toMatchInlineSnapshot(`true`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment