Download spectrum/shared/sort-by-date.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/shared/sort-by-date.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/shared/sort-by-date.js
-
curl -L -o sort-by-date.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/shared/sort-by-date.js
825 Bytes
| /** | |
| * This file is shared between server and client. | |
| * ⚠️ DON'T PUT ANY NODE.JS OR BROWSER-SPECIFIC CODE IN HERE ⚠️ | |
| * | |
| * Note: This uses Flow comment syntax so this whole file is actually valid JS without any transpilation | |
| * The reason I did that is because create-react-app doesn't transpile files outside the source folder, | |
| * so it chokes on the Flow syntax. | |
| * More info: https://flow.org/en/docs/types/comments/ | |
| */ | |
| function sortByDate( | |
| array /*: Array<number> */, | |
| key /*: string */, | |
| order /*: string */ | |
| ) { | |
| return array.sort(function(a, b) { | |
| var x = new Date(a[key]).getTime(); | |
| var y = new Date(b[key]).getTime(); | |
| // desc = older to newest from top to bottom | |
| var val = order === 'desc' ? y - x : x - y; | |
| return val; | |
| }); | |
| } | |
| module.exports = sortByDate; | |