Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make shim-array.js less breaking world around #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions shim-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,47 @@ module.exports = Array;
var array_splice = Array.prototype.splice;
var array_slice = Array.prototype.slice;

Array.empty = [];
if (!Array.empty) {
Array.empty = [];

if (Object.freeze) {
Object.freeze(Array.empty);
if (Object.freeze) {
Object.freeze(Array.empty);
}
}

Array.from = function (values) {
var array = [];
array.addEach(values);
return array;
};
if (!Array.from) {
// Does not compatible with iterators
Array.from = function (values) {
var array = [];
array.addEach(values);
return array;
};
}

Array.unzip = function (table) {
var transpose = [];
var length = Infinity;
// compute shortest row
for (var i = 0; i < table.length; i++) {
var row = table[i];
table[i] = row.toArray();
if (row.length < length) {
length = row.length;
if (!Array.unzip) {
Array.unzip = function (table) {
var transpose = [];
var length = Infinity;
// compute shortest row
for (var i = 0; i < table.length; i++) {
var row = table[i];
table[i] = row.toArray();
if (row.length < length) {
length = row.length;
}
}
}
for (var i = 0; i < table.length; i++) {
var row = table[i];
for (var j = 0; j < row.length; j++) {
if (j < length && j in row) {
transpose[j] = transpose[j] || [];
transpose[j][i] = row[j];
for (var i = 0; i < table.length; i++) {
var row = table[i];
for (var j = 0; j < row.length; j++) {
if (j < length && j in row) {
transpose[j] = transpose[j] || [];
transpose[j][i] = row[j];
}
}
}
}
return transpose;
};
return transpose;
};
}

function define(key, value) {
Object.defineProperty(Array.prototype, key, {
Expand Down