Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active August 29, 2015 14:00
Show Gist options
  • Save kavitshah8/11185561 to your computer and use it in GitHub Desktop.
Save kavitshah8/11185561 to your computer and use it in GitHub Desktop.
I reorganized the node object as an object containing objects. I used particular format because property names are strings, they not sequential integers.
/*
A ---- B ----- C
| |
| |
D ------ E ------ F
*/
var node = {
"A" : {"id": 1, "value": 100, "neighbours": ["D","B"]},
"B" : {"id": 2, "value": 20, "neighbours": ["A","E","C"]},
"C" : {"id": 3, "value": 30, "neighbours": ["B"]},
"D" : {"id": 4, "value": 40, "neighbours": ["A","E"]},
"E" : {"id": 5, "value": 50, "neighbours": ["D","B","F"]}
};
var max = 0;
for( var key in node){
if( max < node[key]["value"] ){
max = node[key]["value"];
}
}
document.getElementById('text').innerHTML = "Maximum is : "+max;
<div id="text"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment