-
Notifications
You must be signed in to change notification settings - Fork 0
/
two-dim-arr.js
123 lines (114 loc) · 4.14 KB
/
two-dim-arr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Generated by CoffeeScript 1.7.1
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], function(_, exports) {
root.TwoDimensionalArray = factory(root, exports);
});
} else if (typeof exports !== "undefined") {
factory(root, exports);
} else {
root.TwoDimensionalArray = factory(root, {});
}
})(this, function(root, TwoDimensionalArray) {
var defaults, extend, previousTwoDimensionalArray;
extend = function(out) {
var arg, key, val, _i, _len;
out || (out = {});
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
arg = arguments[_i];
if (!arg) {
continue;
}
for (key in arg) {
if (!__hasProp.call(arg, key)) continue;
val = arg[key];
out[key] = val;
}
}
return out;
};
defaults = {};
previousTwoDimensionalArray = root.TwoDimensionalArray;
TwoDimensionalArray = (function(_super) {
__extends(TwoDimensionalArray, _super);
function TwoDimensionalArray(param1, param2, options) {
var e, i, j, len1, len2, passThru, settings, _i, _j, _k, _len;
if (param1 instanceof Array && param1[0] instanceof Array) {
options = param2 || {};
passThru = true;
len1 = param1.length;
len2 = param1[0].length;
} else {
len1 = param1;
len2 = param2;
}
settings = extend({}, defaults, options || (options = {}));
this.length = len1;
for (i = _i = 0, _len = this.length; _i < _len; i = ++_i) {
e = this[i];
this[i] = [];
this[i].length = len2;
}
if (settings.value != null) {
for (i = _j = 0; 0 <= len1 ? _j < len1 : _j > len1; i = 0 <= len1 ? ++_j : --_j) {
for (j = _k = 0; 0 <= len2 ? _k < len2 : _k > len2; j = 0 <= len2 ? ++_k : --_k) {
this[i][j] = (function() {
if (passThru) {
return param1[i][j];
} else if (typeof settings.value === "function") {
return settings.value(i, j);
} else {
return settings.value;
}
})();
}
}
}
}
TwoDimensionalArray.prototype.forEach = function(callback) {
var i, item, j, row, _i, _len, _results;
_results = [];
for (i = _i = 0, _len = this.length; _i < _len; i = ++_i) {
row = this[i];
_results.push((function() {
var _j, _len1, _results1;
_results1 = [];
for (j = _j = 0, _len1 = row.length; _j < _len1; j = ++_j) {
item = row[j];
_results1.push(callback(item, i, j, this));
}
return _results1;
}).call(this));
}
return _results;
};
TwoDimensionalArray.prototype.each = function() {
return this.forEach.apply(this, arguments);
};
TwoDimensionalArray.prototype.map = function(callback) {
var i, item, j, map, row, _i, _j, _len, _len1;
map = new TwoDimensionalArray(this.length, this[0].length);
for (i = _i = 0, _len = this.length; _i < _len; i = ++_i) {
row = this[i];
for (j = _j = 0, _len1 = row.length; _j < _len1; j = ++_j) {
item = row[j];
map[i][j] = callback(item, i, j, this);
}
}
return map;
};
TwoDimensionalArray.prototype.size = function() {
return [this.length, this[0].length];
};
return TwoDimensionalArray;
})(Array);
TwoDimensionalArray.noConflict = function() {
root.TwoDimensionalArray = previousTwoDimensionalArray;
return this;
};
return TwoDimensionalArray;
});
}).call(this);