Showing with 36 additions and 0 deletions.
  1. BIN .github/dsa.jpeg
  2. BIN .github/logo.png
  3. +25 −0 src/_Searching_/LinearSearch/LinearSearch.test.js
  4. +11 −0 src/_Searching_/LinearSearch/index.js
Binary file modified .github/dsa.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/_Searching_/LinearSearch/LinearSearch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {linearSearch} = require('./LinearSearch');

describe('Linear Search', () => {
const array = [1, 2, 3, 4, 5, 6, 7, 8];
describe('When element to find is at 1st position ', () => {
it('Linear search', () => {
expect(linearSearch(array, 1)).toEqual(0);
});
});
describe('When element to find is at last position ', () => {
it('Linear search', () => {
expect(linearSearch(array, 8)).toEqual(7);
});
});
describe('When element to find is at random position ', () => {
it('Linear search', () => {
expect(linearSearch(array, 3)).toEqual(2);
});
});
describe('When element to find is no present in array ', () => {
it('Linear search', () => {
expect(linearSearch(array, 10)).toEqual(null);
});
});
})
11 changes: 11 additions & 0 deletions src/_Searching_/LinearSearch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function linearSearch(arr, val) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === val) return i;
}
return null;
}
// MediaSourceHandle.exp
// MediaSourceHandle.expo
module.exports = {
linearSearch
};