Witiko

Množinový kalkulus

Nov 12th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function průnik(a, b, c) {
  2.   var x = [];
  3.   a.forEach(function(item) {
  4.     if(b.indexOf(item) !== -1) x.push(item);
  5.   });
  6.  
  7.   return c?arguments.callee.apply(this,
  8.     Array.prototype.concat.call(
  9.       [x], Array.prototype.slice.call(
  10.         arguments, 2
  11.       )
  12.     )
  13.   ):x;
  14. }
  15.  
  16. function sjednocení(a, b, c) {
  17.   var x = a.slice(0);
  18.   b.forEach(function(item) {
  19.     if(x.indexOf(item) === -1) x.push(item);
  20.   });
  21.  
  22.   return c?arguments.callee.apply(this,
  23.     Array.prototype.concat.call(
  24.       [x], Array.prototype.slice.call(
  25.         arguments, 2
  26.       )
  27.     )
  28.   ):x;
  29. }
  30.  
  31. function rozdíl(a, b, c) {
  32.   var x = [];
  33.   a.forEach(function(item) {
  34.     if(b.indexOf(item) === -1) x.push(item);
  35.   });
  36.  
  37.   return c?arguments.callee.apply(this,
  38.     Array.prototype.concat.call(
  39.       [x], Array.prototype.slice.call(
  40.         arguments, 2
  41.       )
  42.     )
  43.   ):x;
  44. }
  45.  
  46. function symetrickýRozdíl(a, b, c) {
  47.   var x = rozdíl(
  48.     sjednocení(a, b),
  49.     průnik(a, b)
  50.   );
  51.  
  52.   return c?arguments.callee.apply(this,
  53.     Array.prototype.concat.call(
  54.       [x], Array.prototype.slice.call(
  55.         arguments, 2
  56.       )
  57.     )
  58.   ):x;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment