Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Search/LinearSearch/linearsearch2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Program implementing Linear Search

function linear(a,k)
{


var t=0;


for(var i=0; i<a.length; i++)
{
if(k==a[i])
{
t=1;
break; // exit from for-loop if element is found
}
}
if(t==1)
{
return "Element "+a[i]+ " Found at Position:"+i; // return if element is found
}
else
{
return "Element Not Found"; //return if element is not found
}
}

console.log(linear([2,5,6,2,5,3,6,8],56)) // pass array and element to find in array