smath 1.9.2 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SMath = void 0;
4
4
  /**
5
5
  * @packageDocumentation
6
- * ![NPM Downloads](https://img.shields.io/npm/d18m/smath) Small math function library
6
+ * Small math function library
7
+ *
8
+ * ![NPM Downloads](https://img.shields.io/npm/d18m/smath)
7
9
  */
8
10
  /**
9
11
  * Contains a small math function library including
@@ -404,6 +406,7 @@ var SMath;
404
406
  * ```js
405
407
  * const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ]
406
408
  * ```
409
+ * @deprecated Use `SMath.shuffle()` instead
407
410
  */
408
411
  function rseq(min, max) {
409
412
  min |= 0;
@@ -416,6 +419,23 @@ var SMath;
416
419
  return rawData.sort(function (a, b) { return a.index - b.index; }).map(function (a) { return a.value; });
417
420
  }
418
421
  SMath.rseq = rseq;
422
+ /**
423
+ * Randomize an array of arbitrary elements.
424
+ * @param stack An array of arbitrary elements
425
+ * @returns The `stack` array in a random order
426
+ * @example
427
+ * ```js
428
+ * ```
429
+ */
430
+ function shuffle(stack) {
431
+ var rawData = [];
432
+ for (var _i = 0, stack_1 = stack; _i < stack_1.length; _i++) {
433
+ var item = stack_1[_i];
434
+ rawData.push({ index: Math.random(), value: item });
435
+ }
436
+ return rawData.sort(function (a, b) { return a.index - b.index; }).map(function (a) { return a.value; });
437
+ }
438
+ SMath.shuffle = shuffle;
419
439
  /**
420
440
  * Take the limit of a function. A return value of `NaN` indicates
421
441
  * that no limit exists either due to a discontinuity or imaginary value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "1.9.2",
3
+ "version": "1.10.0",
4
4
  "description": "Small math function library",
5
5
  "homepage": "https://npm.nicfv.com/",
6
6
  "bin": "dist/bin.js",
package/types/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @packageDocumentation
3
- * ![NPM Downloads](https://img.shields.io/npm/d18m/smath) Small math function library
3
+ * Small math function library
4
+ *
5
+ * ![NPM Downloads](https://img.shields.io/npm/d18m/smath)
4
6
  */
5
7
  /**
6
8
  * Contains a small math function library including
@@ -270,8 +272,18 @@ export declare namespace SMath {
270
272
  * ```js
271
273
  * const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ]
272
274
  * ```
275
+ * @deprecated Use `SMath.shuffle()` instead
273
276
  */
274
277
  function rseq(min: number, max: number): Array<number>;
278
+ /**
279
+ * Randomize an array of arbitrary elements.
280
+ * @param stack An array of arbitrary elements
281
+ * @returns The `stack` array in a random order
282
+ * @example
283
+ * ```js
284
+ * ```
285
+ */
286
+ function shuffle<T>(stack: Array<T>): Array<T>;
275
287
  /**
276
288
  * Take the limit of a function. A return value of `NaN` indicates
277
289
  * that no limit exists either due to a discontinuity or imaginary value.