Skip to content

Commit

Permalink
fix: incorrect logic, add test groups
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Apr 24, 2019
1 parent 07d2de6 commit f32af1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = function xor(...args) {
if (args.length < 2) {
return false;
}

const truthyCount = args.reduce((result, val) => result + !!val);
return 0 < truthyCount && truthyCount <= (args.length - 1);
return truthyCount === 1;
};
12 changes: 11 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const xor = require('.');

test('examples', () => {
test('not enough arguments', () => {
expect(xor(true)).toBe(false);
expect(xor(false)).toBe(false);
});

test('2 args', () => {
expect(xor(true, false)).toBe(true);
expect(xor(false, true)).toBe(true);
expect(xor(true, true)).toBe(false);
expect(xor(false, false)).toBe(false);
});

test('many arguments', () => {
expect(xor(true, false, false)).toBe(true);
expect(xor(true, true, true)).toBe(false);
expect(xor(true, true, false)).toBe(false);
expect(xor(false, false, false)).toBe(false);
expect(xor(false, false, false, false, false, true)).toBe(true);
});

0 comments on commit f32af1c

Please sign in to comment.