Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 12cbb3868576
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a3efa251cba
Choose a head ref
  • 9 commits
  • 3 files changed
  • 2 contributors

Commits on Feb 27, 2015

  1. Copy the full SHA
    56c6d2e View commit details
  2. Copy the full SHA
    18b0465 View commit details
  3. Copy the full SHA
    bb9b7bf View commit details
  4. Copy the full SHA
    ef7294b View commit details
  5. Copy the full SHA
    dc5e581 View commit details
  6. Copy the full SHA
    579d809 View commit details
  7. Pass "Array#product when given a block will ignore unreasonable numbe…

    …rs of products and yield anyway"
    vais committed Feb 27, 2015
    Copy the full SHA
    f73b804 View commit details
  8. Copy the full SHA
    494cf98 View commit details
  9. Merge pull request #711 from vais/array

    Array#product implementation fully compliant with rubyspec
    meh committed Feb 27, 2015
    Copy the full SHA
    0a3efa2 View commit details
Showing with 52 additions and 9 deletions.
  1. +2 −0 CHANGELOG.md
  2. +50 −0 opal/corelib/array.rb
  3. +0 −9 spec/filters/bugs/array.rb
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

* `String#[]` and `String#slice` implementation fully compliant with rubyspec

* `Array#product` implementation fully compliant with rubyspec

## 0.7.1 2015-02-14

* CLI options `-d` and `-v` now set respectively `$DEBUG` and `$VERBOSE`
50 changes: 50 additions & 0 deletions opal/corelib/array.rb
Original file line number Diff line number Diff line change
@@ -1138,6 +1138,56 @@ def pop(count = undefined)
end
end

def product(*args, &block)
%x{
var result = #{block_given?} ? null : [],
n = args.length + 1,
counters = new Array(n),
lengths = new Array(n),
arrays = new Array(n),
i, m, subarray, len, resultlen = 1;
arrays[0] = self;
for (i = 1; i < n; i++) {
arrays[i] = #{Opal.coerce_to(`args[i - 1]`, Array, :to_ary)};
}
for (i = 0; i < n; i++) {
len = arrays[i].length;
if (len === 0) {
return result || self;
}
resultlen *= len;
if (resultlen > 2147483647) {
#{raise RangeError, "too big to product"}
}
lengths[i] = len;
counters[i] = 0;
}
outer_loop: for (;;) {
subarray = [];
for (i = 0; i < n; i++) {
subarray.push(arrays[i][counters[i]]);
}
if (result) {
result.push(subarray);
} else {
#{yield `subarray`}
}
m = n - 1;
counters[m]++;
while (counters[m] === lengths[m]) {
counters[m] = 0;
if (--m < 0) break outer_loop;
counters[m]++;
}
}
return result || self;
}
end

def push(*objects)
%x{
for (var i = 0, length = objects.length; i < length; i++) {
9 changes: 0 additions & 9 deletions spec/filters/bugs/array.rb
Original file line number Diff line number Diff line change
@@ -81,15 +81,6 @@
fails "Array#permutation returns an Enumerator of permutations of given length when called with an argument but no block"
fails "Array#permutation returns an Enumerator of all permutations when called without a block or arguments"

fails "Array#product when given an empty block returns self"
fails "Array#product when given a block will ignore unreasonable numbers of products and yield anyway"
fails "Array#product when given a block yields all combinations in turn"
fails "Array#product does not attempt to produce an unreasonable number of products"
fails "Array#product returns an empty array when the argument is an empty array"
fails "Array#product has no required argument"
fails "Array#product returns the expected result"
fails "Array#product returns converted arguments using :to_ary"

fails "Array#rassoc does not check the last element in each contained but speficically the second"
fails "Array#rassoc calls elem == obj on the second element of each contained array"