Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rangedSort$

Subhajit Sahu edited this pageMay 3, 2023 ·1 revision

Arrange a range of values in order!

Alternatives:rangedSort,rangedSort$.
Similar:sort,rangedSort,partialSort,rangedPartialSort.


functionrangedSort$(x,i,I,fc,fm,fs)// x:  an array (updated!)// i:  begin index// I:  end index (exclusive)// fc: compare function (a, b)// fm: map function (v, i, x)// fs: swap function (x, i, j)
constxarray=require('extra-array');// Sort a range of values (index 0 to 2).varx=[4,-3,1,-2];xarray.rangedSort$(x,0,2);// → [ -3, 4, 1, -2 ]  (compares numbers, x is updated!)x;// → [ -3, 4, 1, -2 ]// Sort a range of values (index 0 to 3).varx=[4,-3,1,-2];xarray.rangedSort$(x,0,2);// → [ -3, 1, 4, -2 ]// Sort using absolute values.varx=[4,-3,1,-2];xarray.rangedSort$(x,0,3,null,v=>Math.abs(v));// → [ 1, -3, 4, -2 ]


References

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp