Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 2.4 KB

intransigentms-utils-docs.md

File metadata and controls

53 lines (43 loc) · 2.4 KB

What's in intransigentms-utils.min.js/intransigentms-utils.js

jsArray :: java.util.Collection<T> -> Array<T>
jsArray :: java.util.Map<K, V> -> Array<Array(K, V)>
jsArray :: T[] -> Array<T>
jsArray :: byte[] -> Array<Number>
jsArray :: short[] -> Array<Number>
jsArray :: int[] -> Array<Number>
jsArray :: long[] -> Array<Number>
jsArray :: float[] -> Array<Number>
jsArray :: double[] -> Array<Number>
jsArray :: char[] -> Array<java.lang.Character>
jsArray :: boolean[] -> Array<Boolean>

Takes in a java.util.Collection, a java.util.Map, or any native Java array, and converts it to a more or less native JavaScript representation, as an Array.

java.util.Maps are converted to an Array instead of an Object since the java.util.Map may have an ordering (LinkedHashMap, TreeMap). Any java.util.Map's entries are converted to JavaScript 2-tuples (Arrays of length 2).

range :: Number -> Array<Number>
range :: Number, Number -> Array<Number>
range :: Number, Number, Number -> Array<Number>

range(start, end, step) is a function returning an Array of Numbers that represents a "range" between start (inclusive) and end (exclusive). The range steps by increments of step. If step is omitted, it defaults to 1. If, furthermore, end is omitted, end takes the value of start, and start takes the value of 0.

If step is negative or end is less than start (or both), the resulting range is descending. Otherwise the range is ascending.

chooseRandom :: Array<T> -> T
chooseRandom :: Object -> Array(String, T)
chooseRandom :: java.util.Collection<T> -> T
chooseRandom :: java.util.Map<K, V> -> Array(K, V)
chooseRandom :: T[] -> T
chooseRandom :: byte[] -> Number
chooseRandom :: short[] -> Number
chooseRandom :: int[] -> Number
chooseRandom :: long[] -> Number
chooseRandom :: float[] -> Number
chooseRandom :: double[] -> Number
chooseRandom :: char[] -> java.lang.Character
chooseRandom :: boolean[] -> Boolean

Chooses a random element of the provided argument, and returns that element. Like in jsArray, java.util.Maps are treated as a collection of entries, and when an entry is chosen, it is returned as a JavaScript 2-tuple (Array of length 2). Same goes for Objects.

Array.prototype.fisherYates :: () -> Array<T>

Shuffles the array in place using the Fisher-Yates algorithm, and then returns a reference to the array itself.