Skip to content

Commit

Permalink
chore: simplify uniqueArray util
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Jan 18, 2018
1 parent 86fd5bf commit 58c9442
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/checks/aria/allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allowed = axe.commons.aria.allowedAttr(role);
if (Object.keys(options).length) {
for (var roleOption in options) {
if (roleOption === role) {
allowed = axe.utils.uniqueArray(options[role].concat(allowed));
allowed = axe.utils.uniqueArray(options[role], allowed);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (node.hasAttributes()) {
if (Object.keys(options).length) {
for (var roleOption in options) {
if (roleOption === role) {
required = axe.utils.uniqueArray(options[role].concat(required));
required = axe.utils.uniqueArray(options[role], required);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/core/utils/to-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ axe.utils.toArray = function (thing) {


/**
* Creates an array without duplicate values
* @param {Array} arrArg Array to filter
* Creates an array without duplicate values from 2 array inputs
* @param {Array} arr1 First array
* @param {Array} arr2 Second array
* @return {Array}
*/
axe.utils.uniqueArray = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
axe.utils.uniqueArray = (arr1, arr2) => {
return arr1.concat(arr2).filter((elem, pos, arr) => {
return arr.indexOf(elem) === pos;
});
};
2 changes: 1 addition & 1 deletion test/core/utils/to-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('axe.utils.uniqueArray', function () {
var array1 = [1, 2, 3, 4, 5];
var array2 = [1, 3, 7];

var result = axe.utils.uniqueArray(array1.concat(array2));
var result = axe.utils.uniqueArray(array1, array2);
assert.isArray(result);
assert.includeMembers(result, [1, 2, 3, 4, 5, 7]);
});
Expand Down

0 comments on commit 58c9442

Please sign in to comment.