UNPKG

node-dijkstra

Version:

A NodeJS implementation of Dijkstra's algorithm

25 lines (21 loc) 623 B
/** * Removes a key and all of its references from a map. * This function has no side-effects as it returns * a brand new map. * * @param {Map} map - Map to remove the key from * @param {string} key - Key to remove from the map * @return {Map} New map without the passed key */ function removeDeepFromMap(map, key) { const newMap = new Map(); for (const [aKey, val] of map) { if (aKey !== key && val instanceof Map) { newMap.set(aKey, removeDeepFromMap(val, key)); } else if (aKey !== key) { newMap.set(aKey, val); } } return newMap; } module.exports = removeDeepFromMap;