Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sh2aliyev/notes/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Scans each element in order until the target is found or all elements are checked.
TimeSpace
O(n)O(1)

Implementation

Linear Search
function linearSearch(arr, target) {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === target) return i;
  }

  return -1;
}

const numbers = [9, 1, 9, 3, -4, 0, 3, 5, 6, 5];
//               0  1  2  3   4  5  6  7  8  9

console.log(linearSearch(numbers, 5)); // 7

Build docs developers (and LLMs) love