An awesome repository here .
api : masfufa.js
sample : masfufa.html
Two Examples will be enough to understand this library :
Example 1:
/* | 1 , 2 , 3 | * MX= | 4 , 5 , 6 | Dimensions= 3 x 3 * | 7 , 8 , 9 | */ jsdk.getAPI('my'); var A=[1, 2, 3, 4, 5, 6, 7, 8, 9]; var MX=myAPI.getInstance('masfufa',{data:A,dim:'3x3'});
then :
MX.get[0][0] // -> 1 (first) MX.get[2][2] // ->9 (last)
Example 2:
/* | 1 , 9 , 3 , 4 | * MXB= | 4 , 5 , 6 , 2 | Dimensions= 2 x 4 * */ var B=[1 , 9 , 3 , 4 , 4 , 5 , 6 , 2]; var MXB=myAPI.getInstance('masfufa',{data:B,dim:'2x4'});
then :
MXB.get[0][0] // -> 1 (first) MXB.get[1][3] // -> 2 (last) MXB.get[1][2] // -> 6 (before last)
var arr2D = new Array(5).fill(new Array(3));, each element of Array(5) will point to the same Array(3). So it's best to use a for loop to dynamically populate sub arrays.a = Array(5).fill(0).map(x => Array(10).fill(0))filldoesn't callnew Array(3)for each index of the array being filled, since it's not a lambda expression or anything, such as Longfei Wu's comment above, which initially fills the array with 0's, then uses the map function with a lambda to fill each element with a new array. The fill function simply fills the array with exactly what you tell it to. Does that make sense? For more info on themapfunction, see: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…If the new question is a better question or has better answers, then vote to close the old one as a duplicate of the new one.