mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
214 B
JavaScript
11 lines
214 B
JavaScript
7 years ago
|
export const toHash = (array) => {
|
||
|
return array.reduce((hash, item) => {
|
||
|
const id = item.id
|
||
|
if (hash[id]) {
|
||
|
throw new Error('ID already exists')
|
||
|
}
|
||
|
hash[id] = item
|
||
|
return hash
|
||
|
}, {})
|
||
|
}
|