Skip to content

Commit

Permalink
use confirmedArrays when performing intersect (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfisk authored Sep 25, 2020
1 parent 5754b41 commit e24017e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/helpers/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function intersect([...arrays]) {
});
// copied from https://github.com/emberjs/ember.js/blob/315ec6472ff542ac714432036cc96fe4bd62bd1f/packages/%40ember/object/lib/computed/reduce_computed_macros.js#L1063-L1100
let results = confirmedArrays.pop().filter(candidate => {
for (let i = 0; i < arrays.length; i++) {
for (let i = 0; i < confirmedArrays.length; i++) {
let found = false;
let array = arrays[i];
let array = confirmedArrays[i];
for (let j = 0; j < array.length; j++) {
if (array[j] === candidate) {
found = true;
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/helpers/intersect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ module('Integration | Helper | {{intersect}}', function(hooks) {

assert.equal(find('*').textContent.trim(), 'this is all that will render', 'no error is thrown');
});

test('it allows a first parameter null array', async function(assert) {
this.set('array1', null);
this.set('array2', ['foo', 'baz']);

await render(hbs`
this is all that will render
{{#each (intersect array1 array2) as |value|}}
{{value}}
{{/each}}
`);

assert.equal(find('*').textContent.trim(), 'this is all that will render', 'no error is thrown');
});
});

0 comments on commit e24017e

Please sign in to comment.