Iterate lexicographic ordering implementation

This commit is contained in:
Michael Telatynski 2021-06-11 10:33:00 +01:00
parent 21fc386317
commit a4fa2779d4
4 changed files with 180 additions and 61 deletions

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {percentageOf, percentageWithin} from "./numbers";
import { percentageOf, percentageWithin } from "./numbers";
/**
* Quickly resample an array to have less/more data points. If an input which is larger
@ -223,6 +223,21 @@ export function arrayMerge<T>(...a: T[][]): T[] {
}, new Set<T>()));
}
/**
* Moves a single element from fromIndex to toIndex.
* @param list the list from which to construct the new list.
* @param fromIndex the index of the element to move.
* @param toIndex the index of where to put the element.
* @returns A new array with the requested value moved.
*/
export function reorder<T>(list: T[], fromIndex: number, toIndex: number): T[] {
const result = Array.from(list);
const [removed] = result.splice(fromIndex, 1);
result.splice(toIndex, 0, removed);
return result;
}
/**
* Helper functions to perform LINQ-like queries on arrays.
*/