NODE
node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const Network ={
DuportRoad: {Elwa:6,Readlight:1},
Redlight : {Elwa:2,TexaTurnigPoint:1},
Elwa : {CongoTown:5,TexaTurnigPoint :2},
TexaTurnigPoint : {Elwa:2,CongoTown:5},
finish:{}
};
//since the location and destination will varies with change in output
var location ='DuportRoad';
var destination='CongoTown';
var userGraph;
// Assigning to `value` does **not** change the property // value! You need to do `obj[key] = newValue`
function renameKey(obj, fromKey, toKey) {
result = Object.assign({}, Network); // clone so we don't modify the original.
delete result[fromKey];
result[toKey] = obj[fromKey];
return result;
}
for(const key in Network){
if(`${key}`==`${location}`){
userGraph = renameKey(Network,`${key}`,`start`);
break;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run