Permalink
Cannot retrieve contributors at this time
26 lines (22 sloc)
899 Bytes
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/object.groupby/aos/AddValueToKeyedGroup.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var callBound = require('call-bind/callBound'); | |
var GetIntrinsic = require('get-intrinsic'); | |
var SameValue = require('es-abstract/2022/SameValue'); | |
var $TypeError = GetIntrinsic('%TypeError%'); | |
var $filter = callBound('Array.prototype.filter'); | |
var $push = callBound('Array.prototype.push'); | |
module.exports = function AddValueToKeyedGroup(groups, key, value) { | |
var found = $filter(groups, function (group) { | |
return SameValue(group['[[Key]]'], key); // eslint-disable-line new-cap | |
}); | |
if (found.length > 0) { | |
var g = found[0]; | |
if (found.length !== 1) { | |
throw new $TypeError('Assertion failed: more than 1 Record inside `groups` has a `[[Key]]` that is SameValue to `key`'); | |
} | |
$push(g['[[Elements]]'], value); // step 1.a.ii | |
} else { | |
var group = { '[[Key]]': key, '[[Elements]]': [value] }; // eslint-disable-line sort-keys | |
$push(groups, group); // step 3 | |
} | |
}; |