I'm new to testing and NodeJS and I'd like to test the output in console.log using assert.deepEqual
to test whether or not the result has correct data.
For example, I've written a code that flatten multidimensional array.
var mixedArray = [0, {1: 2}, 3, [4, 5, [6, 7]], 8];
function flatten(arr) {
var result = [];
function _flatten(arr) {
var array = arr;
var length = arr.length;
for (var i=0; i<length; i++) {
if (!Array.isArray(array[i])) {
result.push(array[i]);
} else if (length !== 'undefined' ){
_flatten(array[i]);
} else break;
}
}
_flatten(arr);
console.log(result);
return result;
}
Console.log
output:
Array [ 0, Object, 3, 4, 5, 6, 7, 8 ]
NodeJS output:
[ 0, { '1': 2 }, 3, 4, 5, 6, 7, 8 ]