UNPKG

map-fns

Version:

<h1 align="center"> <code>map-fns</code> </h1>

35 lines (32 loc) 920 B
'use strict'; /** * Takes in two maps and returns true if they contain the same keys and the * values behind their keys are shallowly equal. Returns false otherwise. * * This function can be useful to check if changes have occurred in any of * the items in the map. * * The order that the maps are provided in does not matter. * * @param a First map to compare * @param b Second map to compare * @returns True if they are equal, False if they are not */ function areMapsShallowEqual(a, b) { var aKeys = Object.keys(a); var bKeys = Object.keys(b); if (aKeys.length !== bKeys.length) { return false; } for (var i = 0; i < aKeys.length; i += 1) { var key = aKeys[i]; if (!b.hasOwnProperty(key)) { return false; } if (a[key] !== b[key]) { return false; } } return true; } module.exports = areMapsShallowEqual;