Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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 ]

share|improve this question
    
Hi, and welcome to Code Review - where working code is reviewed. Are you asking for help to write the unit tests (which makes this question off-topic because the code does not yet work), or have you just forgotten to include them as part of your question (in which case it's off-topic because the code is not included in the question)? Do you need to edit in the code? –  rolfl Jun 10 at 3:06
    
Hello @rolfl this is actually a working code. When I run this function, I get a different output in NodeJS vs. console.log –  markisnil Jun 10 at 3:33

1 Answer 1

Your two outputs are different representation of the same data. Depending on the console you output to Object can be expanded and it's contents viewed (for example: chrome's console output).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.