Linear Search
Linear search is one of the simplest search algorithms. It checks each item in a list one by one until it finds the target value or reaches the end of the list.
How it works
- Start at the beginning of the array.
- Compare the current item with the target.
- If they match, return the index.
- If no match is found, return
-1.
Example
function linearSearch(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) {
return i;
}
}
return -1;
}
console.log(linearSearch([10, 20, 30, 40], 30)); // 2
Time complexity
- Best case:
O(1) - Average case:
O(n) - Worst case:
O(n)
When to use it
Linear search is useful for small arrays or unsorted data where simplicity matters more than speed.
More in algorithms
Continue exploring articles in this category.
Aug 14, 2025
Binary Search
Learn how Binary Search works in JavaScript — step-by-step examples, O(log n) time complexity analysis, sorted…
Aug 21, 2025
Divide And Conquer Pattern
Understanding the Divide and Conquer pattern in JavaScript — how it splits problems into subproblems, with com…
Jul 24, 2025
Understanding the Frequency Counter Pattern in JavaScript
A deep dive into the Frequency Counter pattern in JavaScript — how it replaces nested loops, reduces time comp…
Case Study
Bible Verse — Case Study
Production SaaS Platform · Full-Stack · Founder & Sole Engineer
A domain-driven SaaS platform with five independently scalable system boundaries: scripture content delivery, RAG-backed AI study, real-time community interaction, async media processing, and infrastructure services — built and operated end-to-end.
Our Results
How We Built It
- RAG pipeline grounding AI responses in actual scripture rather than model memory
- Hybrid Llama / OpenAI routing — local inference for cost, API fallback for quality at the edge
- Non-blocking media processing — FFmpeg jobs enqueued via BullMQ, API never waits on transcoding
- Cross-instance real-time consistency via Redis pub/sub behind WebSocket and WebRTC layers
Lessons Learned
- Domain boundaries enforced at the service layer prevent coupling long before scale demands microservices.
- RAG retrieval quality matters more than model size — better embeddings outperform a larger model on poor context.
- Async queue design should be first-class, not bolted on; BullMQ worker isolation saved the request path repeatedly.
Stack
Written by
5+ years building production systems · AI, Backend & Infrastructure · Founder of Bible Logic
Full-stack engineer with 5+ years of hands-on experience designing and shipping production systems — from Nuxt 3 frontends and Nitro APIs to self-hosted Kubernetes clusters, RAG pipelines, and real-time AI applications. Everything I write comes from systems I've designed, deployed, and operated in production.

