mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
26 lines
667 B
JavaScript
26 lines
667 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* 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 (array && array.isMatrix === true) {
|
|
array = array.valueOf();
|
|
}
|
|
|
|
for (var i = 0, ii = array.length; i < ii; i++) {
|
|
var value = array[i];
|
|
|
|
if (Array.isArray(value)) {
|
|
deepForEach(value, callback);
|
|
}
|
|
else {
|
|
callback(value);
|
|
}
|
|
}
|
|
};
|