DEV Community

pawan deore
pawan deore

Posted on

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)