Created
February 7, 2022 06:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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