MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / sortObj

Method sortObj

src/danfojs-base/shared/utils.ts:810–857  ·  view source on GitHub ↗

* Custom sort for an array of index and values * @param arr The array of objects to sort * @param ascending Whether to sort in ascending order or not

(
        arr: Array<{ index: number | string, value: number | string | boolean }>,
        ascending: boolean
    )

Source from the content-addressed store, hash-verified

808 * @param ascending Whether to sort in ascending order or not
809 */
810 sortObj(
811 arr: Array<{ index: number | string, value: number | string | boolean }>,
812 ascending: boolean
813 ) {
814 let sortedValues = arr.sort((obj1, obj2) => {
815 let a = obj2.value;
816 let b = obj1.value;
817
818 if (!ascending) {
819 if (typeof a === "string" && typeof b === "string") {
820 a = a.toUpperCase();
821 b = b.toUpperCase();
822
823 if (a < b) {
824 return -1;
825 }
826
827 if (a > b) {
828 return 1;
829 }
830
831 return 0;
832
833 } else {
834 return Number(a) - Number(b);
835 }
836 } else {
837 if (typeof a === "string" && typeof b === "string") {
838 a = a.toUpperCase();
839 b = b.toUpperCase();
840
841 if (a > b) {
842 return -1;
843 }
844
845 if (a < b) {
846 return 1;
847 }
848
849 return 0;
850 } else {
851 return Number(b) - Number(a);;
852 }
853 }
854 });
855
856 return sortedValues;
857 }
858}

Callers 2

sortValuesMethod · 0.80
sortIndexMethod · 0.80

Calls 2

sortMethod · 0.80
toUpperCaseMethod · 0.80

Tested by

no test coverage detected