const searchPath = require('../helpers/dijkstra_algo'); const cities = require('../data/test_data/cities'); const roads = require('../data/test_data/roads'); let { path, distance} = searchPath(cities, roads, 1, 9); const formatedPath = []; // I didn't use map or filter because it doesn't preserve the order for (let path_city of path) { for (let city of cities) { if (city.id == path_city) { formatedPath.push({ id: city.id, name: city.name }); } } } console.log(formatedPath)