app.d 424 B

123456789101112131415161718
  1. T[] find(T)(T[] haystack, T needle)
  2. {
  3. while (haystack.length > 0 && haystack[0] != needle)
  4. {
  5. haystack = haystack[1 .. $];
  6. }
  7. return haystack;
  8. }
  9. unittest
  10. {
  11. // Проверка способностей к обобщению
  12. double[] d = [ 1.5, 2.4 ];
  13. assert(find(d, 1.0) == null);
  14. assert(find(d, 1.5) == d);
  15. string[] s = [ "one", "two" ];
  16. assert(find(s, "two") == [ "two" ]);
  17. }