Created
May 30, 2021 10:46
-
-
Save djmin43/489a0105261fb950f231c9d57edaa78d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// SORT BY DATE (TOGGLE) | |
const sortByDate = () => { | |
if (new Date(inventory[0].expiration_date).valueOf() < new Date(inventory[inventory.length -1 ].expiration_date).valueOf()) { | |
const sortedInventory = inventory.slice(0).sort((a: Inventory, b:Inventory) => {return new Date(b.expiration_date).valueOf() - new Date(a.expiration_date).valueOf()}) | |
setInventory(sortedInventory) | |
} else { | |
const sortedInventory = inventory.slice(0).sort((a: Inventory, b:Inventory) => {return new Date(a.expiration_date).valueOf() - new Date(b.expiration_date).valueOf()}) | |
setInventory(sortedInventory) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment