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

Method sortValues

src/danfojs-base/core/series.ts:828–858  ·  view source on GitHub ↗
(options?: { ascending?: boolean, inplace?: boolean })

Source from the content-addressed store, hash-verified

826 */
827 sortValues(options?: { ascending?: boolean, inplace?: boolean }): Series
828 sortValues(options?: { ascending?: boolean, inplace?: boolean }): Series | void {
829 const { ascending, inplace, } = { ascending: true, inplace: false, ...options }
830
831 let sortedValues = [];
832 let sortedIndex = []
833 const rangeIdx = utils.range(0, this.index.length - 1);
834 let sortedIdx = utils.sortArrayByIndex(rangeIdx, this.values, this.dtypes[0]);
835
836 for (let indx of sortedIdx) {
837 sortedValues.push(this.values[indx])
838 sortedIndex.push(this.index[indx])
839 }
840
841 if (ascending) {
842 sortedValues = sortedValues.reverse();
843 sortedIndex = sortedIndex.reverse();
844 }
845
846 if (inplace) {
847 this.$setValues(sortedValues as ArrayType1D)
848 this.$setIndex(sortedIndex);
849 } else {
850 const sf = new Series(sortedValues, {
851 index: sortedIndex,
852 dtypes: this.dtypes,
853 config: this.config
854 });
855 return sf;
856
857 }
858 }
859
860
861 /**

Callers 1

argSortMethod · 0.95

Calls 4

sortArrayByIndexMethod · 0.80
$setValuesMethod · 0.80
$setIndexMethod · 0.65
rangeMethod · 0.45

Tested by

no test coverage detected