DEV Community

pawan deore
pawan deore

Posted on

2 1

perform Linear and Binary Search in one line !

alright is you want to perform search algorithm in one line well my friend you will need search-ray npm library

Steps : You will need NodeJS installed on your pc if you have then skip this step

Now install library using npm

npm install search-ray
Enter fullscreen mode Exit fullscreen mode

create on simple folder and file named anything you like, copy below code init and run that JS files to get Output!

1] for linear search


const search = require('search-ray');
console.log(search.linearSearch([1,2,3,5],5))   // [3]

Enter fullscreen mode Exit fullscreen mode

2] for Binary search


const search = require('search-ray');
console.log(search.binarySearch([1,2,3,5],5))   // 3

Enter fullscreen mode Exit fullscreen mode

and thats it my friend thanks..
follow me for such tutorials!
https://twitter.com/pawandeore7

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post