## Array RubyNice version to add methods directly to the class by monkey patching * [Array](#Array) * [.eachWithIndex(loop_function)](#Array+eachWithIndex) → Array.<any> * [.flatten()](#Array+flatten) → [Array](#Array) * [.getFirst()](#Array+getFirst) → any * [.getLast()](#Array+getLast) → any * [.getMax()](#Array+getMax) → number \| null * [.getMin()](#Array+getMin) → number \| null * [.getSample()](#Array+getSample) → any ### array.eachWithIndex(loop_function) → Array.<any> Iterates over all elements of the array Breaks if returning false **Returns**: Array.<any> - returns itself | Param | Type | | --- | --- | | loop_function | [eachArrayLoopCallback](#eachArrayLoopCallback) | **Example** ```js ['one','two','three'].eachWithIndex((elem, index) => { if(condition) return false; console.log(elem); }) ``` ### array.flatten() → [Array](#Array) Returns a new array that is a one dimensional flattening of itself. Different to Javascript flat(), which only flattens one dimension. ### array.getFirst() → any Returns the first element of the array **Example** ```js ['one','two','three'].getFirst() // => 'one' ``` ### array.getLast() → any Returns the last element of the array **Example** ```js ['one','two','three'].getLast() // => 'three' ``` ### array.getMax() → number \| null Returns the max element of the array. All values must be of type number. **Returns**: number \| null - returns null if array is empty **Example** ```js [3,7,2].getMax() // => 7 ``` ### array.getMin() → number \| null Returns the min element of the array. All values must be of type number. **Returns**: number \| null - returns null if array is empty **Example** ```js [3,7,2,9].getMin() // => 2 ``` ### array.getSample() → any Returns a random element of the array **Example** ```js ['one','two','three'].getSample() // => 'two' ``` ## flatten() → [Array](#Array) Returns a new array that is a one dimensional flattening of itself. Different to Javascript flat(), which only flattens one dimension. ## getMax() → number \| null Returns the max element of the array. All values must be of type number. **Returns**: number \| null - returns null if array is empty **Example** ```js [3,7,2].getMax() // => 7 ``` ## getMin() → number \| null Returns the min element of the array. All values must be of type number. **Returns**: number \| null - returns null if array is empty **Example** ```js [3,7,2,9].getMin() // => 2 ``` ## eachArrayLoopCallback : function **Kind**: global typedef | Param | Type | | --- | --- | | value | any | | index | number |