UNPKG

service-utilities

Version:

Utility Package for FIORI UI5

32 lines (29 loc) 759 B
/** * @module ArrayExpansion * @description Utilities for Array * @author jpanti * @version 1.0.0 * @created 2025-08-01 * @lastModified 2025-08-01 * @license ISC */ sap.ui.define([], () => { "use strict"; return { shuffle(arr) { // Shuffle using Fisher–Yates algorithm for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i [arr[i], arr[j]] = [arr[j], arr[i]]; // swap } return arr; }, arrange(aData, aIndex, cbTransform = (oData) => oData) { const result = Array(aData.length); for (let i = 0; i < aData.length; i++) { result[aIndex[i]] = cbTransform(aData[i]); } return result; }, }; });