proto-objectsarray
v0.11.0
Published
General purpose Library to prototype the Array object to utilize analysing data stored as array of objects
Downloads
6
Maintainers
Readme
proto-objectsArray
General Purpose Library To Prototype The Array Object To Utilize Analysing Data Stored As Array Of Objects.
usage :
var proto = require('proto-objectsarray'); //require the Library
proto(); // load the Library
var testArray=[{"fName":"Adam","age":22,"rank":3,"lName":"juma"},
{"fName":"salim","age":33,"rank":2,"lName":"juma"},
{"fName":"mohd","age":25,"rank":5,"lName":"rida"}];
Then for any Array of objects within your code you may use the functions as detailed in below examples.
� .seek("lName","juma","fname","Adam")
//returns {"fName":"Adam","age":22,"rank":3,"lName":"juma"}
In case more than one object is found it returns an array of the found objects. e.g.:
testArray.seek("lName","juma")
// note that you may use one or two seek parameters only.
it returns :[{"fName":"Adam","age":22,"rank":3,"lName":"juma"},{"fName":"salim","age":33,"rank":2,"lName":"juma"}]
In case no objects where found it returns -1 if three arguments are used it will return the value of array of values for the third argument in the objects that meet the condition of the first two arguments e.g. :
testArray.seek("lName","rida","fname")
//it will return "mohd"
testArray.seek("lName","juma","fname")
//it will return ["Adam","salim"]
� .seekSlim()// same as .seek but for the first search condition you may search partially e.g.
testArray.seekSlim("lName","ju","fname","Adam")
//it returns {"fName":"Adam","age":22,"rank":3,"lName":"juma"}
testArray.seekSlim("lName","ri","fname")
//it returns "mohd"
� .seekA() same as .seek but forces the return of an Array even if one result is found e.g.
testArray.seekA("lName","juma","fname","Adam")
//returns :[{"fName":"Adam","age":22,"rank":3,"lName":"juma"}]
//it returns [] if no results are found.
� .INDEX() same as seekA but returns the INDEX of the object in the array not the object and always returns an array or -1 e.g.:
testArray.INDEX("lName","juma")
// it returns :[0,1]
� .maxOf() takes odd number of arguments (1,3 or 5) if one argument is provided it seeks the maximum value of this argument.e.g:
testArray.maxOf("rank") // returns 5;
if 3 or 5 arguments are provided the considered maximum value is the last argument and the others are equivalence conditions e.g.
testArray.maxOf("lName","juma","fName","Adam","age")
// returns 22
� .minOf() // same as maxOf but with the minimum value.
� .rowOf(columnIndex,value) * It may be replaced by seekSlim()* Returns the row that has the same "value" in the property with index that matches "columnIndex" e.g:
testArray.rowOf(2,33)
// returns {"fName":"salim","age":33,"rank":2,"lName":"juma"}
testArray.rowOf("age",33)
//' returns {"fName":"salim","age":33,"rank":2,"lName":"juma"}
testArray.rowOf("fName","salim")
//returns {"fName":"salim","age":33,"rank":2,"lName":"juma"}
testArray.rowOf("fName","sal")
//returns {"fName":"salim","age":33,"rank":2,"lName":"juma"}
it returns an object if one item is found and an array if many and and empty array if none is found.
� .numSort() // Sorts and Array of objects following one Numerical property e.g:
testArray.numSort("age")
// if no second argument is provided it sorts Ascending .
testArray.numSort("age","A") or testArray.numSort("age","D") the second arguments takes only two options : "A" for Ascending and "D" for Descending.