npmtest-mout (v0.0.1)

Code coverage report for node-npmtest-mout/node_modules/mout/array/sortBy.js

Statements: 44.44% (4 / 9)      Branches: 0% (0 / 4)      Functions: 0% (0 / 2)      Lines: 44.44% (4 / 9)      Ignored: none     

All files » node-npmtest-mout/node_modules/mout/array/ » sortBy.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211 1         1                   1        
var sort = require('./sort');
var makeIterator = require('../function/makeIterator_');
 
    /*
     * Sort array by the result of the callback
     */
    function sortBy(arr, callback, context){
        callback = makeIterator(callback, context);
 
        return sort(arr, function(a, b) {
            a = callback(a);
            b = callback(b);
            return (a < b) ? -1 : ((a > b) ? 1 : 0);
        });
    }
 
    module.exports = sortBy;