@@ -2,7 +2,7 @@ import { isCollection, isMatrix } from './is.js'
22import { IndexError } from '../error/IndexError.js'
33import { arraySize , findFirst as arrayFindFirst } from './array.js'
44import { _switch } from './switch.js'
5- import { forEach as iterableForEach } from './iterable.js'
5+ import { forEach as iterableForEach , map as iterableMap } from './iterable.js'
66
77/**
88 * Test whether an array contains collections
@@ -56,28 +56,11 @@ export function deepForEach (array, callback) {
5656 * @return {Array | Matrix } res
5757 */
5858export function deepMap ( array , callback , skipZeros ) {
59- if ( skipZeros ) {
60- const callbackSkip = ( x ) => x === 0 ? 0 : callback ( x )
61- if ( isMatrix ( array ) ) {
62- return array . create ( recurse ( array . valueOf ( ) , callbackSkip ) , array . datatype ( ) )
63- } else {
64- return recurse ( array , callbackSkip )
65- }
59+ const callbackSkip = skipZeros ? x => x === 0 ? 0 : callback ( x ) : x => callback ( x )
60+ if ( isMatrix ( array ) ) {
61+ return array . map ( callbackSkip )
6662 } else {
67- if ( isMatrix ( array ) ) {
68- return array . create ( recurse ( array . valueOf ( ) , callback ) , array . datatype ( ) )
69- } else {
70- return recurse ( array , callback )
71- }
72- }
73- function recurse ( array ) {
74- if ( Array . isArray ( array ) ) {
75- return array . map ( function ( x ) {
76- return recurse ( x )
77- } )
78- } else {
79- return callback ( array )
80- }
63+ return iterableMap ( array , callbackSkip , false , false , array )
8164 }
8265}
8366
0 commit comments