Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: knaxus/problem-solving-javascript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: vishvas04/problem-solving-javascript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Mar 7, 2025

  1. Added the JS code on how to perform Linear Search and also created a …

    …test file where all the test cases are being mentioned under the searching folder
    vishvas04 committed Mar 7, 2025
    Copy the full SHA
    b9c0727 View commit details
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
};