Skip to content

Instantly share code, notes, and snippets.

@rohangeorge91
Created February 7, 2022 06:37
Show Gist options
  • Save rohangeorge91/c398d6e63fd9b61509eebae15fc67394 to your computer and use it in GitHub Desktop.
Save rohangeorge91/c398d6e63fd9b61509eebae15fc67394 to your computer and use it in GitHub Desktop.
An interesting way to store 2 days of the week in a 64 bits.
// lookup <- one time cost
let dict = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
// gives the two days based on the number
const getDay = (num) => ([(num % 7), (num / (7 - (num % 7)))]).map((val) => dict[val]);
// based on the days as mentioned above
const getNum = (arr) => [1]
.concat(arr.map((val) => dict.lastIndexOf(val)))
.reduce((acc, val) => (acc * val));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment