You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Splits an amount among multiple people based on a percentage criterion specified.
*
* @param {float} amount - Amount to be split
* @param {object} percentagesByPeople - An object whose each key is a person identifier and value is a number between 0 and 1 indicating the person's split.
* @return {object} - An object whose each key is a person identifier as specified in the input. Each value indicates the person's split amount.
*/
module.exports=(amount,percentagesByPeople)=>{
constpeople=keys(percentagesByPeople);
constpercentages=values(percentagesByPeople);
letsplitAmountByPeople={};
if(amount<=0){
thrownewError('amount cannot be zero or negative');
}
if(!isObject(percentagesByPeople)){
thrownewError('percentage splits must be an object');