Last active
August 29, 2015 14:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="text"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment