1.0.3 • Published 8 years ago

hash-choose v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

hash-choose

Exports a function that returns a function that maps a hash function to values, defaults to values(maphash(string)) if no key in map matches the hash and hash returns an integer.

##installation:

npm install --save hash-choose

##usage:

const hashChoose = require('hash-choose');
const getValue = hashChoose({
    map: {
        123: 'foo',
        234: 'bar',
        345: 'baz'
    },
    hash: x => x + 100
});
getValue(23); // 'foo'
getValue(134); // 'bar'
getValue(134); // 'bar'
getValue(700); // values(map)[(700 + 100) % 3] => 'baz'
getValue(899); // values(map)[(899 + 100) % 3] => 'foo'