some-right.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. module.exports = {
  3. __generic: function (t, a) {
  4. var count = 0, first, last, x, icount = this.length;
  5. t.call(this, function (item, index, col) {
  6. ++count;
  7. if (!first) {
  8. first = item;
  9. }
  10. last = item;
  11. x = col;
  12. a(index, --icount, "Index");
  13. });
  14. a(count, this.length, "Iterated");
  15. a(first, this[this.length - 1], "First is last");
  16. a(last, this[0], "Last is first");
  17. a.deep(x, Object(this), "Collection as third argument"); //jslint: skip
  18. },
  19. "": function (t, a) {
  20. var x = {}, y, count;
  21. t.call([1], function () { y = this; }, x);
  22. a(y, x, "Scope");
  23. y = 0;
  24. t.call([3, 4, 4], function (a, i) { y += i; });
  25. a(y, 3, "Indexes");
  26. x = [1, 3];
  27. x[5] = 'x';
  28. y = 0;
  29. count = 0;
  30. a(t.call(x, function (a, i) { ++count; y += i; }), false, "Return");
  31. a(y, 6, "Misssing Indexes");
  32. a(count, 3, "Misssing Indexes, count");
  33. count = 0;
  34. a(t.call([-2, -3, -4, 2, -5], function (item) {
  35. ++count;
  36. return item > 0;
  37. }), true, "Return");
  38. a(count, 2, "Break after true is returned");
  39. }
  40. };