array-hash
v1.0.2
Published
hash is javascript utility
Downloads
4
Maintainers
Readme
Hash!
Hash is JavaScript Array Utility
Install
npm install array-hash
Function
Collection
Util
Etc
Simple Exam
var H = require('Array-Hash');
var arr = [1, 2, 3, 36, 56, 53, 4, 5, 6, 10, 14, 21];
var result = H(arr).filter(function(item) { return item%2 == 0 }).max(4).toList({ sort: 'asc' });
output : [10, 14, 36, 56]
Document
Collection
H([1, 2, 3]).forEach(function(item) {
// code
});
var arr = H([1, 2, 3]).filter(function(item) { return item%2 == 0 });
output : H([2])
var max = H([1, 2, 3]).max();
output : 3
max-range
var max = H([1, 2, 3]).max(2);
output : H([3, 2])
var min = H([1, 2, 3]).min();
output : 3
min-range
var min = H([1, 2, 3]).min(2);
output : H([3, 2])
var sum = H([1, 2, 3]).sum();
output : 6
var sum = H([1, 2, 3]).sum(2);
output : H([3, 4, 5])
var mul = H([1, 2, 3]).mul();
output : 6
var mul = H([1, 2, 3]).mul(2);
output : H([2, 4, 6])
var avg = H([1, 2, 3]).avg();
output : 2
var result = H([1, 2, 3]).isAll(function(item) { return item > 0 });
output : true
var result = H([1, 2, 3]).isSome(function(item) { return item == 1 });
output : true
var result = H([1, 2, 3]).isNone(function(item) { return item == 0 });
output : true
var result = H([1, 2, 3]).contains(3);
output : true
Util
var result = H([1, 2, 3]).join("-");
output : 1-2-3
var result = H([1, 2, 3]).slice(2);
output : 13
var result = H([1, 2, 3]).first();
output : 1
var result = H([1, 2, 3]).last();
output : 3
var arr = H.range(1, 10);
output : H([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
var arr = H.range(1, 10, 1);
output : H([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
Etc
var arr = H([1, 2, 3]).isList();
output : [1, 2, 3]