UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

27 lines (22 loc) 682 B
'use strict' const isMatrix = require('./isMatrix') /** * Recursively loop over all elements in a given multi dimensional array * and invoke the callback on each of the elements. * @param {Array | Matrix} array * @param {Function} callback The callback method is invoked with one * parameter: the current element in the array */ module.exports = function deepForEach (array, callback) { if (isMatrix(array)) { array = array.valueOf() } for (let i = 0, ii = array.length; i < ii; i++) { const value = array[i] if (Array.isArray(value)) { deepForEach(value, callback) } else { callback(value) } } }