/* * Create a data source */ create(source, data = {}, sort = []) { let database = this.read(source); database.push(_.merge({}, data, {id: hasher(data)})); // Sort if we have to if (!_.isEmpty(sort)) database = _.orderBy(database, ...sort); // Dump results this.yaml.dump(path.resolve(this.base, `${source}.yml`), _.uniqBy(database, 'id')); return this.read(source, {id: hasher(data)}); }
// Helper to get a base for our dynamic opts, eg things that will change based on source/recipe selection const auxOpts = recipes => ({name: nameOpts, recipe: recipeOpts(_.orderBy(recipes)), webroot: webrootOpts})
getAutoCompleteSites(answers, lando, input).then(sites => { return _.orderBy(sites, ['name', 'desc']); })
.then(networks => _.slice(_.orderBy(networks, 'Created', 'asc'), 0, 5))
// USERS TO EXPLORE app.post('/get-users-to-explore', async (req, res) => { let { id } = req.session, _users = await db.query( 'SELECT users.id, users.username, users.firstname, users.surname FROM users WHERE users.id <> ? ORDER BY RAND() DESC LIMIT 12', [id] ), users = [] for (let u of _users) { let isFollowing = await User.isFollowing(id, u.id), [{ followers_count }] = await db.query( 'SELECT COUNT(follow_id) AS followers_count FROM follow_system WHERE follow_to=?', [u.id] ), mutualUsers = await User.mutualUsers(id, u.id) !isFollowing ? users.push({ ...u, followers_count, mutualUsersCount: mutualUsers.length, }) : [] } let orderByMutualUsers = _.orderBy(users, ['mutualUsersCount'], ['desc']) res.json(orderByMutualUsers) })
let orderByMutualUsers = _.orderBy( filter.slice(0, 5), ['mutualUsersCount'],
// GROUPS TO EXPLORE app.post('/get-groups-to-explore', async (req, res) => { let { id } = req.session, _groups = await db.query( 'SELECT group_id, name, admin, created FROM groups ORDER BY RAND()' ), groups = [] for (let g of _groups) { let [{ membersCount }] = await db.query( 'SELECT COUNT(grp_member_id) AS membersCount FROM group_members WHERE group_id=?', [g.group_id] ), mutualMembers = await Group.mutualGroupMembers(id, g.group_id), joined = await Group.joinedGroup(id, g.group_id) !joined ? groups.push({ ...g, membersCount, mutualMembersCount: mutualMembers.length, joined, }) : [] } let orderByMutualMembers = _.orderBy(groups, ['mutualMembersCount'], ['desc']) res.json(orderByMutualMembers) })
const findReviewersByState = (reviews, state) => { // filter out review submitted comments because it does not nullify an approved state. // Other possible states are PENDING and REQUEST_CHANGES. At those states the user has not approved the PR. // See https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request // While submitting a review requires the states be PENDING, REQUEST_CHANGES, COMMENT and APPROVE // The payload actually returns the state in past tense: i.e. APPROVED, COMMENTED const relevantReviews = reviews.filter(element => element.state.toLowerCase() !== 'commented') // order it by date of submission. The docs says the order is chronological but we sort it so that // uniqBy will extract the correct last submitted state for the user. const ordered = _.orderBy(relevantReviews, ['submitted_at'], ['desc']) const uniqueByUser = _.uniqBy(ordered, 'user.login') // approved reviewers are ones that are approved and not nullified by other submissions later. return uniqueByUser .filter(element => element.state.toLowerCase() === state) .map(review => review.user && review.user.login) }
getForRecipient(address) { const mails = this.mailSummaries.get(address) || [] return _.orderBy(mails, mail => Date.parse(mail.date), ['desc']) }
/** * Exports the orderBy function. * @module sql-processors/orderBy * @requires lodash */ /** * Executes the SQL ORDER BY statement on an Array of Objects * @param {Array} columns - An Array of Strings, containing the columns that should get ordered. * @param {Array} orders - An Array of Strings, containing the orders for the columns. * @param {Array} data - The Array of Objects on which the ORDER BY statement should be executed. * @returns {Array} - An Array of Objects in the specified order. */ const orderBy = (columns, orders, data) => { if (columns.length > 0 && orders.length > 0) { const lowerOrders = orders.map(order => order.toLowerCase()) return _.orderBy(data, columns, lowerOrders) } return data }
function useMultiple(list) { // Use one or more map, concatAll, and filter calls to create an array with the following items // [ // {"id": 675465,"title": "Fracture","boxart":"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg" }, // {"id": 65432445,"title": "The Chamber","boxart":"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg" }, // {"id": 654356453,"title": "Bad Boys","boxart":"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" }, // {"id": 70111470,"title": "Die Hard","boxart":"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" } // ] let results = _.flatMap(list, l => _.map(l.videos, v => { return { id: v.id, title: v.title, boxart: _.filter(v.boxarts, function(boxc) { return boxc.width === 150 }).reduce(function(prev, curr) { return curr.url }, ''), } }), ) results = _.orderBy(results, ['id', 'title'], ['asc']) return results }
let sortedBidsByHighestPrice = _.orderBy(JSON.parse(JSON.stringify(bids)), ['current_bid'], ['desc']) let theWinnerDetail = sortedBidsByHighestPrice[0]
let spendableOutput = _.orderBy(unspentOutputs, 'amountSatoshi', 'desc')[0]
getAll() { const mails = [...this.mailSummaries.values()] return _.orderBy(mails, mail => Date.parse(mail.date), ['desc']) }
function useMultiple(list) { // Use one or more map, concatAll, and filter calls to create an array with the following items // [ // {"id": 675465,"title": "Fracture","boxart":"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg" }, // {"id": 65432445,"title": "The Chamber","boxart":"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg" }, // {"id": 654356453,"title": "Bad Boys","boxart":"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" }, // {"id": 70111470,"title": "Die Hard","boxart":"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" } // ] let results = _.flatMap(list, l => _.map(l.videos, v => { return { id: v.id, title: v.title, boxart: _.filter(v.boxarts, function(boxc) { return boxc.width === 150 }).reduce(function(prev, curr) { return curr.url }, ''), } }), ) results = _.orderBy(results, ['id', 'title'], ['asc']) return results }