I have a logic problem with this javascript, for example
var stone = [
[1,1,2,1,1],
[2,3,2,2,2],
[4,5,5,5,5],
[6,6,6,7,6],
[8,8,8,8,9]
];
How to find the different number and also the position/order of number in the array, and return the variable that contain the information like
var stone = [['number's order','the different number'],[..]];
and the result, variable would be like
var stone = [
[2,2],
[1,3],
[0,4],
[3,7],
[4,9]
];
I look for days to solved and learned this with looping condition "for", but I have lack of basic javascript logic and Im not even close. How can I do this, anyone can help?
I only can reach on this stage, when I tried to break down the index and still looking for the algorithm and stuck
function display(num) {
$('#test').append($('<div>').text(num));
}
var batu = [
[1,1,2,1,1],
[2,3,2,2,2],
[4,5,5,5,5],
[6,6,6,7,6],
[8,8,8,8,9]
];
for(var i = 0; i < batu.length; i++) {
var bt = batu[i];
for(var j = 0; j < bt.length; j++) {
display("bt[" + i + "][" + j + "] = " + bt[j]);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="test"></div>
Thanks in advance