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

Extended Euclidean Algorithm #200

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added if number is Even or Odd
amitsingh19975 committed Sep 3, 2018
commit e6ee494c20ba0ed616c48fd98fca0c7271ff63d1
30 changes: 30 additions & 0 deletions src/algorithms/math/bits/__test__/isEven.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import isEven from '../isEven';

describe('isEven', () => {
it('should get if number is even or not', () => {
// 2 = true
// 3 = false
expect(isEven(2)).toBe(true);
expect(isEven(3)).toBe(false);

// 5 = odd
// 6 = even
expect(isEven(5)).toBe(false);
expect(isEven(6)).toBe(true);

// 7 = odd
// 8 = even
expect(isEven(7)).toBe(false);
expect(isEven(8)).toBe(true);

// 9 = odd
// 10 = even
expect(isEven(9)).toBe(false);
expect(isEven(10)).toBe(true);

// 11 = odd
// 12 = even
expect(isEven(11)).toBe(false);
expect(isEven(12)).toBe(true);
});
});
8 changes: 8 additions & 0 deletions src/algorithms/math/bits/isEven.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @param {number} number
* @param {number} bitPosition - zero based.
* @return {number}
*/
export default function isEven(number) {
return ((number & 1) === 0);
}