Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 9192fdd

Browse files
shan7030Kent C. Dodds
authored andcommitted
feat(BitwiseAnd): Add BitwiseAnd function (#212)
1 parent 486268f commit 9192fdd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/BitwiseAnd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default BitwiseAnd
2+
3+
/**
4+
* Original Source: https://stackoverflow.com/a/35211814
5+
*
6+
* This method will revers the order of a the chars in a string.
7+
*
8+
* @param {Array} array - Array
9+
* @returns {Number} - Bitwise And of all the operations
10+
*/
11+
function BitwiseAnd(array) {
12+
return array.reduce((a, b) => {
13+
return a & b //eslint-disable-line no-bitwise
14+
})
15+
}
16+
17+

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import temperatureConverter from './temperatureConverter'
7878
import last from './last'
7979
import descendingOrder from './descending-order'
8080
import reduceCount from './reduceCount'
81+
import BitwiseAnd from './BitwiseAnd'
8182

8283
export {
8384
reverseArrayInPlace,
@@ -160,4 +161,5 @@ export {
160161
last,
161162
descendingOrder,
162163
reduceCount,
164+
BitwiseAnd,
163165
}

test/BitwiseAnd.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import test from 'ava'
2+
import {BitwiseAnd} from '../src'
3+
4+
test('Returns the Bitwise And of all the Array Elements', t => {
5+
const name1=[1,3,5]
6+
const actual = BitwiseAnd(name1)
7+
const expected=1
8+
t.deepEqual(actual, expected)
9+
})
10+
11+

0 commit comments

Comments
 (0)