jsonQ.js
function(list, elm, isQualifier) {
            var type = objType(elm),
                ln = list.length,
                //check that elm is a object or not that is taken by reference
                refObj = type == "object" || type == "array" || type == "function" ? true : false;


            //if elm is a function consider it as a qualifier
            if (type == "function") {
                isQualifier = true;
            }

            if (refObj && !isQualifier) {
                //convert object to string so that they can be compared.
                var jsonStr = stringify(jsonQ.order(elm));
            }

            for (var i = 0; i < ln; i++) {
                var cur = list[i];
                if (refObj) {
                    var lType = objType(cur);
                    if (lType != type && !isQualifier) continue;

                    //to compare
                    if (!isQualifier) {
                        if (stringify(jsonQ.order(cur)) == jsonStr) {
                            return i;
                        }

                        //if element is a qualifier
                    } else {
                        var test;
                        if (type == 'function') {
                            test = elm.call(cur);
                        } else if (type == "object" && lType == "object") {
                            test = jsonQ.checkKeyValue(cur, elm);
                        } else if (lType == "array") {
                            if (type == "array") {
                                for (var j = 0, elmLn = elm.length; j < elmLn; j++) {
                                    test = jsonQ.index(cur, elm[j]) != -1;
                                    if (!test) break;
                                }
                            } else {
                                test = jsonQ.index(cur, elm) != -1;
                            }
                        }

                        //return index if it passes the test
                        if (test) return i;

                    }

                } else if (elm == cur) {
                    return i;
                }
            }
            return -1;
        }
function(list, elm, isQualifier) {
            var type = objType(elm),
                ln = list.length,
                //check that elm is a object or not that is taken by reference
                refObj = type == "object" || type == "array" || type == "function" ? true : false;


            //if elm is a function consider it as a qualifier
            if (type == "function") {
                isQualifier = true;
            }

            if (refObj && !isQualifier) {
                //convert object to string so that they can be compared.
                var jsonStr = stringify(jsonQ.order(elm));
            }

            for (var i = 0; i < ln; i++) {
                var cur = list[i];
                if (refObj) {
                    var lType = objType(cur);
                    if (lType != type && !isQualifier) continue;

                    //to compare
                    if (!isQualifier) {
                        if (stringify(jsonQ.order(cur)) == jsonStr) {
                            return i;
                        }

                        //if element is a qualifier
                    } else {
                        var test;
                        if (type == 'function') {
                            test = elm.call(cur);
                        } else if (type == "object" && lType == "object") {
                            test = jsonQ.checkKeyValue(cur, elm);
                        } else if (lType == "array") {
                            if (type == "array") {
                                for (var j = 0, elmLn = elm.length; j < elmLn; j++) {
                                    test = jsonQ.index(cur, elm[j]) != -1;
                                    if (!test) break;
                                }
                            } else {
                                test = jsonQ.index(cur, elm) != -1;
                            }
                        }

                        //return index if it passes the test
                        if (test) return i;

                    }

                } else if (elm == cur) {
                    return i;
                }
            }
            return -1;
        }
function ( list , elm , isQualifier ) { var type = objType ( elm ) , ln = list . length , //check that elm is a object or not that is taken by reference refObj = type == "object" || type == "array" || type == "function" ? true : false ; //if elm is a function consider it as a qualifier if ( type == "function" ) { isQualifier = true ; } if ( refObj && ! isQualifier ) { //convert object to string so that they can be compared. var jsonStr = stringify ( jsonQ . order ( elm ) ) ; } for ( var i = 0 ; i < ln ; i ++ ) { var cur = list [ i ] ; if ( refObj ) { var lType = objType ( cur ) ; if ( lType != type && ! isQualifier ) continue ; //to compare if ( ! isQualifier ) { if ( stringify ( jsonQ . order ( cur ) ) == jsonStr ) { return i ; } //if element is a qualifier } else { var test ; if ( type == 'function' ) { test = elm . call ( cur ) ; } else if ( type == "object" && lType == "object" ) { test = jsonQ . checkKeyValue ( cur , elm ) ; } else if ( lType == "array" ) { if ( type == "array" ) { for ( var j = 0 , elmLn = elm . length ; j < elmLn ; j ++ ) { test = jsonQ . index ( cur , elm [ j ] ) != - 1 ; if ( ! test ) break ; } } else { test = jsonQ . index ( cur , elm ) != - 1 ; } } //return index if it passes the test if ( test ) return i ; } } else if ( elm == cur ) { return i ; } } return - 1 ; }
to find index of an element in set of element
to find index of an element in set of element