const { shuffle, map } = require('lodash') const { sendMessages } = require('./send-email') const input = shuffle(require('./input.json')) function assign (array) { return map(array, (person, index, array) => { const friend = array[index + 1] || array[0] return { person, friend } }) } sendMessages(assign(input)) .then(result => { console.log(result) }) .catch(err => { console.error(err) })