collection-delete-all.js 586 B

1234567891011121314151617
  1. 'use strict';
  2. var call = require('../internals/function-call');
  3. var aCallable = require('../internals/a-callable');
  4. var anObject = require('../internals/an-object');
  5. // https://github.com/tc39/collection-methods
  6. module.exports = function deleteAll(/* ...elements */) {
  7. var collection = anObject(this);
  8. var remover = aCallable(collection['delete']);
  9. var allDeleted = true;
  10. var wasDeleted;
  11. for (var k = 0, len = arguments.length; k < len; k++) {
  12. wasDeleted = call(remover, collection, arguments[k]);
  13. allDeleted = allDeleted && wasDeleted;
  14. }
  15. return !!allDeleted;
  16. };