You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
705 B

const lodashOrderBy = require('lodash.orderby')
const assign = require('assign-deep')
/**
* reduce results
*
* @param {object} options
* @param {object} results
*
* @return {object}
*
*/
function reduce(options, results) {
options = assign({
offset: 0,
limit: results.length
}, options)
// check if offset exists and limit is smaller then length
if (options.offset > 0 && options.limit < results.length) {
options.limit += options.offset
// if new limit is more then length, then set to length
if (options.limit > results.length) {
options.limit = results.length
}
}
// offset and limit
return results.slice(options.offset, options.limit)
}
module.exports = reduce