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.

Here is the original question where the user asks how to create an empty matrix. One of the answers is the following

/**
* Generates a matrix (ie: 2-D Array) with: 
* 'm' columns, 
* 'n' rows, 
* every cell defaulting to 'd';
*/
function Matrix(m, n, d){
   var mat = Array.apply(null, new Array(m)).map(
        Array.prototype.valueOf,
        Array.apply(null, new Array(n)).map(
            function() {
               return d;
            }
        )
     );
    return mat;
}

This certainly works. But can anyone explain me step by step what exactly going on in this code?

share|improve this question

closed as off-topic by SirPython, Ismael Miguel, Vogel612, Heslacher, Mast Aug 31 at 14:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Welcome to Code Review! Unfortunately, since you are looking for an explanation of your code, this post is off-topic. –  SirPython Aug 31 at 14:40
2  
Welcome To Code Review, as SirPython already mentioned, explanations of code are off-topic. For more information, please check the help center. If you have open questions after that, feel free to drop by in our Code Review Chat –  Vogel612 Aug 31 at 14:41

Browse other questions tagged or ask your own question.