@@ -10,7 +10,7 @@ import { deepStrictEqual } from './object.js'
1010 * This function checks the size of the first entry, it does not validate
1111 * whether all dimensions match. (use function `validate` for that)
1212 * @param {Array } x
13- * @Return {Number[]} size
13+ * @return {Number[] } size
1414 */
1515export function arraySize ( x ) {
1616 const s = [ ]
@@ -28,7 +28,7 @@ export function arraySize (x) {
2828 * has a size corresponding to the provided size array.
2929 * @param {Array } array Array to be validated
3030 * @param {number[] } size Array with the size of each dimension
31- * @param {number } dim Current dimension
31+ * @param {number } dim Current dimension
3232 * @throws DimensionError
3333 * @private
3434 */
@@ -51,7 +51,7 @@ function _validate (array, size, dim) {
5151 _validate ( array [ i ] , size , dimNext )
5252 }
5353 } else {
54- // last dimension. none of the childs may be an array
54+ // last dimension. none of the children may be an array
5555 for ( i = 0 ; i < len ; i ++ ) {
5656 if ( Array . isArray ( array [ i ] ) ) {
5757 throw new DimensionError ( size . length + 1 , size . length , '>' )
@@ -82,7 +82,7 @@ export function validate (array, size) {
8282
8383/**
8484 * Validate whether the source of the index matches the size of the Array
85- * @param {Array | Matrix } array Array to be validated
85+ * @param {Array | Matrix } value Array to be validated
8686 * @param {Index } index Index with the source information to validate
8787 * @throws DimensionError
8888 */
@@ -113,8 +113,8 @@ export function validateIndex (index, length) {
113113}
114114
115115/**
116- * Test if and index has empty values
117- * @param {number } index Zero-based index
116+ * Test if an index has empty values
117+ * @param {Index } index Zero-based index
118118 */
119119export function isEmptyIndex ( index ) {
120120 for ( let i = 0 ; i < index . _dimensions . length ; ++ i ) {
@@ -140,7 +140,7 @@ export function isEmptyIndex (index) {
140140 * Resize a multi dimensional array. The resized array is returned.
141141 * @param {Array | number } array Array to be resized
142142 * @param {number[] } size Array with the size of each dimension
143- * @param {* } [defaultValue=0] Value to be filled in in new entries,
143+ * @param {* } [defaultValue=0] Value to be filled in new entries,
144144 * zero by default. Specify for example `null`,
145145 * to clearly see entries that are not explicitly
146146 * set.
@@ -180,7 +180,7 @@ export function resize (array, size, defaultValue) {
180180 * @param {Array } array Array to be resized
181181 * @param {number[] } size Array with the size of each dimension
182182 * @param {number } dim Current dimension
183- * @param {* } [defaultValue] Value to be filled in in new entries,
183+ * @param {* } [defaultValue] Value to be filled in new entries,
184184 * undefined by default.
185185 * @private
186186 */
@@ -283,7 +283,7 @@ export function reshape (array, sizes) {
283283
284284/**
285285 * Replaces the wildcard -1 in the sizes array.
286- * @param {number[] } sizes List of sizes for each dimension. At most on wildcard.
286+ * @param {number[] } sizes List of sizes for each dimension. At most one wildcard.
287287 * @param {number } currentLength Number of elements in the array.
288288 * @throws {Error } If more than one wildcard or unable to replace it.
289289 * @returns {number[] } The sizes array with wildcard replaced.
@@ -333,7 +333,7 @@ function _reshape (array, sizes) {
333333 // testing if there are enough elements for the requested shape
334334 let tmpArray = array
335335 let tmpArray2
336- // for each dimensions starting by the last one and ignoring the first one
336+ // for each dimension starting by the last one and ignoring the first one
337337 for ( let sizeIndex = sizes . length - 1 ; sizeIndex > 0 ; sizeIndex -- ) {
338338 const size = sizes [ sizeIndex ]
339339 tmpArray2 = [ ]
@@ -408,7 +408,7 @@ function _squeeze (array, dims, dim) {
408408/**
409409 * Unsqueeze a multi dimensional array: add dimensions when missing
410410 *
411- * Paramter `size` will be mutated to match the new, unqueezed matrix size.
411+ * Parameter `size` will be mutated to match the new, unsqueezed matrix size.
412412 *
413413 * @param {Array } array
414414 * @param {number } dims Desired number of dimensions of the array
@@ -442,7 +442,7 @@ export function unsqueeze (array, dims, outer, size) {
442442 * @param {Array } array
443443 * @param {number } dims Required number of dimensions
444444 * @param {number } dim Current dimension
445- * @returns {Array | * } Returns the squeezed array
445+ * @returns {Array | * } Returns the unsqueezed array
446446 * @private
447447 */
448448function _unsqueeze ( array , dims , dim ) {
@@ -554,7 +554,7 @@ export function filter (array, callback) {
554554}
555555
556556/**
557- * Filter values in a callback given a regular expression
557+ * Filter values in an array given a regular expression
558558 * @param {Array } array
559559 * @param {RegExp } regexp
560560 * @return {Array } Returns the filtered array
@@ -671,7 +671,7 @@ export function getArrayDataType (array, typeOf) {
671671
672672/**
673673 * Return the last item from an array
674- * @param {array }
674+ * @param {Array } array
675675 * @returns {* }
676676 */
677677export function last ( array ) {
@@ -680,16 +680,16 @@ export function last (array) {
680680
681681/**
682682 * Get all but the last element of array.
683- * @param {array }
684- * @returns {* }
683+ * @param {Array } array
684+ * @returns {Array }
685685 */
686686export function initial ( array ) {
687687 return array . slice ( 0 , array . length - 1 )
688688}
689689
690690/**
691691 * Recursively concatenate two matrices.
692- * The contents of the matrices is not cloned.
692+ * The contents of the matrices are not cloned.
693693 * @param {Array } a Multi dimensional array
694694 * @param {Array } b Multi dimensional array
695695 * @param {number } concatDim The dimension on which to concatenate (zero-based)
@@ -719,8 +719,8 @@ function concatRecursive (a, b, concatDim, dim) {
719719 * Concatenates many arrays in the specified direction
720720 * @param {...Array } arrays All the arrays to concatenate
721721 * @param {number } concatDim The dimension on which to concatenate (zero-based)
722- * @returns
723- */
722+ * @returns { Array }
723+ */
724724export function concat ( ) {
725725 const arrays = Array . prototype . slice . call ( arguments , 0 , - 1 )
726726 const concatDim = Array . prototype . slice . call ( arguments , - 1 )
@@ -736,9 +736,9 @@ export function concat () {
736736}
737737
738738/**
739- * Receives two or more sizes and get's the broadcasted size for both.
739+ * Receives two or more sizes and gets the broadcasted size for both.
740740 * @param {...number[] } sizes Sizes to broadcast together
741- * @returns
741+ * @returns { number[] } The broadcasted size
742742 */
743743export function broadcastSizes ( ...sizes ) {
744744 const dimensions = sizes . map ( ( s ) => s . length )
@@ -773,17 +773,17 @@ export function checkBroadcastingRules (size, toSize) {
773773 const n = N - dim + j
774774 if ( ( size [ j ] < toSize [ n ] && size [ j ] > 1 ) || ( size [ j ] > toSize [ n ] ) ) {
775775 throw new Error (
776- `shape missmatch: missmatch is found in arg with shape (${ size } ) not possible to broadcast dimension ${ dim } with size ${ size [ j ] } to size ${ toSize [ n ] } `
776+ `shape mismatch: mismatch is found in arg with shape (${ size } ) not possible to broadcast dimension ${ dim } with size ${ size [ j ] } to size ${ toSize [ n ] } `
777777 )
778778 }
779779 }
780780}
781781
782782/**
783783 * Broadcasts a single array to a certain size
784- * @param {array } array Array to be broadcasted
784+ * @param {Array } array Array to be broadcasted
785785 * @param {number[] } toSize Size to broadcast the array
786- * @returns The broadcasted array
786+ * @returns { Array } The broadcasted array
787787 */
788788export function broadcastTo ( array , toSize ) {
789789 let Asize = arraySize ( array )
@@ -815,11 +815,11 @@ export function broadcastTo (array, toSize) {
815815/**
816816 * Broadcasts arrays and returns the broadcasted arrays in an array
817817 * @param {...Array | any } arrays
818- * @returns
818+ * @returns { Array[] } The broadcasted arrays
819819 */
820820export function broadcastArrays ( ...arrays ) {
821821 if ( arrays . length === 0 ) {
822- throw new Error ( 'Insuficient number of argumnets in function broadcastArrays' )
822+ throw new Error ( 'Insufficient number of arguments in function broadcastArrays' )
823823 }
824824 if ( arrays . length === 1 ) {
825825 return arrays [ 0 ]
@@ -832,11 +832,11 @@ export function broadcastArrays (...arrays) {
832832}
833833
834834/**
835- * stretches a matrix up to a certain size in a certain dimension
835+ * Stretches a matrix up to a certain size in a certain dimension
836836 * @param {Array } arrayToStretch
837- * @param {number[] } sizeToStretch
837+ * @param {number } sizeToStretch
838838 * @param {number } dimToStretch
839- * @returns
839+ * @returns { Array } The stretched array
840840 */
841841export function stretch ( arrayToStretch , sizeToStretch , dimToStretch ) {
842842 return concat ( ...Array ( sizeToStretch ) . fill ( arrayToStretch ) , dimToStretch )
@@ -846,13 +846,13 @@ export function stretch (arrayToStretch, sizeToStretch, dimToStretch) {
846846* Retrieves a single element from an array given an index.
847847*
848848* @param {Array } array - The array from which to retrieve the value.
849- * @param {Array<number> } idx - An array of indices specifying the position of the desired element in each dimension.
849+ * @param {Array<number> } index - An array of indices specifying the position of the desired element in each dimension.
850850* @returns {* } - The value at the specified position in the array.
851851*
852852* @example
853853* const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
854854* const index = [1, 0, 1];
855- * console.log(getValue (arr, index)); // 6
855+ * console.log(get (arr, index)); // 6
856856*/
857857export function get ( array , index ) {
858858 if ( ! Array . isArray ( array ) ) { throw new Error ( 'Array expected' ) }
@@ -886,7 +886,7 @@ export function recurse (value, index, array, callback) {
886886/**
887887 * Deep clones a multidimensional array
888888 * @param {Array } array
889- * @returns cloned array
889+ * @returns { Array } cloned array
890890 */
891891export function clone ( array ) {
892892 return Object . assign ( [ ] , array )
0 commit comments