# Code explanation please!

**URL:** <https://forum.kirupa.com/t/code-explanation-please/294830>\
**Category:** Uncategorized\
**Created:** [August 20, 2009, 3:38pm UTC](https://forum.kirupa.com/t/code-explanation-please/294830 "2009-08-20T15:38:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arelle](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@Arelle](https://forum.kirupa.com/u/Arelle)\
**Post date:** [August 20, 2009, 3:38pm UTC](https://forum.kirupa.com/t/code-explanation-please/294830/1 "2009-08-20T15:38:38Z")

</div>

maxTiles = 20;  
cardsMatched = 0;  
map = new Array();

function sortByWeight(a,b) {  
if (a[1] \> b[1]) {return 1;}  
else if (a[1] \< b[1]) {return -1;}  
else {return 0;}  
}  
for (var i=0; i\<maxTiles; i++) {  
map\* = new Array(i, Math.random());  
}  
map.sort(sortByWeight);

// insert tiles  
for (var i=0; i\<maxTiles; i++) {  
\_root[“tile”+i].pics.gotoAndStop(map\*[0]+1);  
//\_root[“tile”+i].pics.gotoAndStop(i+1);  
\_root[“tile”+i].itemNumber = Math.floor(map\*[0] / 2);  
}

can someone please tell me what (map\*[0]+1); in the inserting tiles does? i dont quite understand arrays. pics is a movieclip that contains different images on each frame.

also can you explain the last line of code coz i dont understand it at all?!

Thanks!!
