JavaScript Remove set of values in an existing Set remove existing values,php array remove existing values

In JavaScript, I have the following Sets:

var mySet = new Set(["foo", "bar", "baz"]);
var valuesToRemove = new Set(["foo", "baz"]);

I need a function that removes a set of values:

removeAll(mySet, valuesToRemove);
// expected value of mySet: Set ["bar"]

// or a function that returns a new Set
var myNewSet = removeAll(mySet, valuesToRemove);
// expected value of myNewSet: Set ["bar"]

Question: Does any ES6-modules-compatible library exists that does the trick?

Lodash has a similar function for Arrays, but supporting JavaScript builtin iterable is tagged as wontfix. And I prefer to avoid doing multiple Array↔Set/Set↔Array conversions.

Alternatively, I will write my own function.

Answer:1

It is much easier to write your own function than use a library for a single lightweight functionality:

var mySet = new Set(["foo", "bar", "baz"]);
var valuesToRemove = new Set(["foo", "baz"]);

function removeAll(originalSet, toBeRemovedSet) {
  [...toBeRemovedSet].forEach(function(v) {
    originalSet.delete(v); 
  });
}

console.log([...mySet]);
removeAll(mySet, valuesToRemove);
console.log([...mySet]);
Answer:2

You could use Set#forEach directly with the set and delete then the value from the other set.

var mySet = new Set(["foo", "bar", "baz"]);
var valuesToRemove = new Set(["foo", "baz"]);

function removeAll(originalSet, toBeRemovedSet) {
    toBeRemovedSet.forEach(Set.prototype.delete, originalSet);
}

console.log([...mySet]);
removeAll(mySet, valuesToRemove);
console.log([...mySet]);
Answer:3

I have a MongoDB database with many documents in a collection. Each of those articles has a field called myField containing a string. Is it possible for me to run a bulk update on all documents in ...

I have a MongoDB database with many documents in a collection. Each of those articles has a field called myField containing a string. Is it possible for me to run a bulk update on all documents in ...

  1. mongodb update string to date
  2. mongodb update string to objectid
  3. mongodb update string to int
  4. mongodb update string replace
  5. mongodb update string to array
  6. mongodb update string append
  7. mongodb update string to number
  8. mongodb update string
  9. mongodb update concat string
  10. mongodb update convert string to date
  11. mongodb update part of string
  12. mongodb update field append string

I'm following the example exactly as shown in https://github.com/marcshilling/react-native-image-picker using react-native-image-picker, via terminal with react-native run-ios and coding via Atom ...

I'm following the example exactly as shown in https://github.com/marcshilling/react-native-image-picker using react-native-image-picker, via terminal with react-native run-ios and coding via Atom ...

  1. react native image picker
  2. react native image background
  3. react native image resizemode
  4. react native image crop picker
  5. react native image cache
  6. react native image not showing
  7. react native image gallery
  8. react native image viewer
  9. react native image upload
  10. react native image onpress
  11. react native image svg
  12. react native image editor
  13. react native image carousel
  14. react native image zoom
  15. react native image resize
  16. react native image slider
  17. react native image button
  18. react native image base64
  19. react native image loading
  20. react native image view

I'm stumped.. I tested this method with another object that contains a nested array in the console, and got the expected results db_status_emitter.on("components_found", function (returned_item) { ...

I'm stumped.. I tested this method with another object that contains a nested array in the console, and got the expected results db_status_emitter.on("components_found", function (returned_item) { ...

I have the following link_to helper: # app/views/users/show.html.erb <div id="social"> <%= link_to "Friends", index_friends_path, id: "index_friends", remote: true %> </div> ...

I have the following link_to helper: # app/views/users/show.html.erb <div id="social"> <%= link_to "Friends", index_friends_path, id: "index_friends", remote: true %> </div> ...