mirror of
https://github.com/photonstorm/phaser
synced 2025-01-25 19:35:15 +00:00
32 lines
777 B
JavaScript
32 lines
777 B
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
*/
|
|
|
|
/**
|
|
* Takes the given array and runs a numeric sort on it, ignoring any non-digits that
|
|
* may be in the entries.
|
|
*
|
|
* You should only run this on arrays containing strings.
|
|
*
|
|
* @function Phaser.Utils.Array.SortByDigits
|
|
* @since 3.50.0
|
|
*
|
|
* @param {string[]} array - The input array of strings.
|
|
*
|
|
* @return {string[]} The sorted input array.
|
|
*/
|
|
var SortByDigits = function (array)
|
|
{
|
|
var re = /\D/g;
|
|
|
|
array.sort(function (a, b)
|
|
{
|
|
return (parseInt(a.replace(re, ''), 10) - parseInt(b.replace(re, ''), 10));
|
|
});
|
|
|
|
return array;
|
|
};
|
|
|
|
module.exports = SortByDigits;
|