bitburner-src/src/Locations/createCityMap.ts

20 lines
606 B
TypeScript
Raw Normal View History

/**
* Utility function that creates a "city map", which is an object where
* each city is a key (property).
*
* This map uses the official name of the city, NOT its key in the 'Cities' object
*/
import { Cities } from "./Cities";
import { IMap } from "../types";
export function createCityMap<T>(initValue: T): IMap<T> {
2021-10-26 23:43:35 +02:00
const map: IMap<T> = {};
2021-09-05 01:09:30 +02:00
const cities = Object.keys(Cities);
for (let i = 0; i < cities.length; ++i) {
map[cities[i]] = initValue;
}
2021-10-26 23:43:35 +02:00
// round try JSON so to make sure none of the initial values have the same references.
return JSON.parse(JSON.stringify(map));
}