mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
14 lines
391 B
CoffeeScript
14 lines
391 B
CoffeeScript
# Convert an array of objects into a hash, indexed by the objects' ids
|
|
#
|
|
# producers = [{id: 1, name: 'one'}, {id: 2, name: 'two'}]
|
|
# Indexer.index producers
|
|
# -> {1: {id: 1, name: 'one'}, 2: {id: 2, name: 'two'}}
|
|
|
|
angular.module("ofn.admin").factory 'Indexer', ->
|
|
new class Indexer
|
|
index: (data, key='id') ->
|
|
index = {}
|
|
for e in data
|
|
index[e[key]] = e
|
|
index
|