algorithm-helpers
is a collection of JavaScript algorithms for common programming tasks. It includes implementations of binary search and Kadane's algorithm.
You can install algorithm-helpers
via npm:
const { binarySearch } = require('algorithm-helpers');
const arr = [1, 3, 5, 7, 9]; console.log(binarySearch(arr, 5)); // Output: 2
const { kadanceAlgorithm } = require('algorithm-helpers');
const arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]; console.log(kadanceAlgorithm(arr)); // Output: 6
Performs a binary search on a sorted array arr to find the index of target. Returns the index of target if found, otherwise returns -1.
Finds the maximum sum of a contiguous subarray within the array arr using Kadane's algorithm. Returns the maximum sum found.