for-each-right.js 896 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(
  22. [1],
  23. function () {
  24. y = this;
  25. },
  26. x
  27. );
  28. a(y, x, "Scope");
  29. y = 0;
  30. t.call([3, 4, 4], function (a, i) {
  31. y += i;
  32. });
  33. a(y, 3, "Indexes");
  34. x = [1, 3];
  35. x[5] = "x";
  36. y = 0;
  37. count = 0;
  38. t.call(x, function (a, i) {
  39. ++count;
  40. y += i;
  41. });
  42. a(y, 6, "Misssing Indexes");
  43. a(count, 3, "Misssing Indexes, count");
  44. }
  45. };