Advertisement
Savelyev_Vyacheslav

Untitled

Nov 28th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // < метод set аналог в python >
  2. function set(max, min=[]){
  3. function uniqFun(val) {return val.filter((element, index, array) => array.indexOf(element) === index);}
  4. var uniq = {
  5. set1: function() {this.set1 = uniqFun(max)},
  6. set2: function() {this.set2 = uniqFun(min)},
  7. minus: function() {
  8. const namesArr = this.set1;
  9. const namesToDeleteArr = this.set2;
  10. const namesToDeleteSet = new Set(namesToDeleteArr);
  11. return namesArr.filter((name) => {
  12. return !namesToDeleteSet.has(name);
  13. });
  14. },
  15. plus: function(){
  16. const set1 = this.set1;
  17. const set2 = this.set2;
  18. const set3 = set1.concat(set2);
  19. return uniqFun(set3)
  20. }
  21. }
  22. uniq.set1(); uniq.set2();
  23. return uniq
  24. }
  25. // < / метод set аналог в python >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement