https://github.com/bttmly/ordered-map
an ordered map
https://github.com/bttmly/ordered-map
Last synced: 3 months ago
JSON representation
an ordered map
- Host: GitHub
- URL: https://github.com/bttmly/ordered-map
- Owner: bttmly
- License: mit
- Created: 2014-11-05T07:26:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-27T01:52:50.000Z (about 10 years ago)
- Last Synced: 2025-01-08T22:01:53.027Z (4 months ago)
- Language: CoffeeScript
- Size: 332 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ordered Map [](https://travis-ci.org/nickb1080/ordered-map)
## Methods
### `push(key, value) => Number size`
Adds `value` indexed by `key` to the map in the last position. If `key` is already in map, removes `key` before pushing.### `pop() => value`
Removes the last mapping, and returns the `value`. If map is empty, returns `null`.### `unshift(key, value) => Number size`
Add `value` indexed by `key` to the map in the first position. If `key` is already in map, removes `key` before unshifting.### `shift() => value`
Removes the first mapping, and returns the `value`. If map is empty, returns `null`.### `get(key) => value`
Returns the `value` for `key`, or `undefined`. Key access is O(1).### `update(key, value) => `
Changes the value associated with `key` without changing the order.### `remove(key) => Number size`
Deletes the key-value pair indexed by `key`.### `keys() => Array keyStrings`
Returns an array containing the map's keys.### `forEach(cb) => undefined`
Calls `cb(key, value)` for each key-value pair in the map.### `has(key) => Boolean hasKey`
Returns a boolean indicating whether or not `key` is in the map. Uses the [`in` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in) under the hood.### `at(Number index) => value`
Returns the value for the key at position `index` (zero-indexed, naturally). Random access is O(n) due to linked list traversal.### `clear() => undefined`
Removes all keys and values from the map.### `first() => value`
Returns the first value in the map without removing it.### `last() => value`
Returns the last value in the map without removing it.