JSPM

day_2_assignment_binary_search

1.0.2
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 2
    • Score
      100M100P100Q12260F
    • License ISC

    Binary Search DSA Algorithum

    Package Exports

    • day_2_assignment_binary_search
    • day_2_assignment_binary_search/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (day_2_assignment_binary_search) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Binary Search Algorithm

    A simple npm package for performing binary search on arrays.

    Installation

    You can install this package via npm:

    npm install day_2_assignment_binary_search
    
    const binarySearch = require('day_2_assignment_binary_search');
    
    // Example 1: Searching in a sorted array
    const sortedArray = [1, 3, 5, 7, 9];
    const target1 = 7;
    const index1 = binarySearch(sortedArray, target1);
    console.log(`Target ${target1} found at index ${index1}`);
    
    // Example 2: Searching in an unsorted array
    const unsortedArray = [9, 2, 5, 1, 7];
    const target2 = 5;
    const index2 = binarySearch(unsortedArray, target2);
    console.log(`Target ${target2} found at index ${index2}`);
    
    // Example 3: Target not found
    const target3 = 4;
    const index3 = binarySearch(sortedArray, target3);
    if (index3 === -1) {
      console.log(`Target ${target3} not found`);
    }