ossiejhmoore

Untitled

May 22nd, 2023
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2.  
  3. List foo = {1,2,9,10,11,12,8}
  4. List bar = {3,4,5,6,7,8}
  5.  
  6.  
  7. echo( IsAnyOverlap(foo,bar) )
  8.  
  9.  
  10.  
  11. function Boolean IsAnyOverlap( List a, List b )
  12. Boolean found = FALSE
  13. List inner
  14. List outter
  15. Dynamic item
  16.  
  17.  
  18. if ( ( IsDefined( a ) ) || ( IsDefined( b ) ) )
  19.  
  20. //it doesn't matter which is outter, so make smaller one of the two outter
  21.  
  22. if ( Length( a ) < Length( b ) )
  23.  
  24. outter = a
  25. inner = b
  26.  
  27. else
  28.  
  29. outter = b
  30. inner = a
  31.  
  32. end
  33.  
  34. for item in outter
  35.  
  36. found = item in inner
  37.  
  38. if ( found )
  39.  
  40. break
  41.  
  42. end
  43.  
  44. end
  45.  
  46. end
  47.  
  48. return found
  49.  
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment