When i'm trying buildGraph function with normal function its working properly but with arrow function getting empty obj as output. Help needed.
var roads = [
"Alice's House-Bob's House", "Alice's House-Cabin",
"Alice's House-Post Office", "Bob's House-Town Hall",
"Daria's House-Ernie's House", "Daria's House-Town Hall",
"Ernie's House-Grete's House", "Grete's House-Farm",
"Grete's House-Shop", "Marketplace-Farm",
"Marketplace-Post Office", "Marketplace-Shop",
"Marketplace-Town Hall", "Shop-Town Hall"
];
let buildGraph = (edges) => {
let obj = {}
let addEdge = (from, to) => (
obj[from] === null ? obj[from] = [to] : obj[from]?.push(to)
)
edges.map(r => r.split("-")).map(([from, to]) => addEdge(from, to))
return obj;
}
console.log(buildGraph(roads)) // Output: {}