Answers for "JavaScript Implementation of Linear Search"

1

JavaScript Implementation of Linear Search

function linearSearch(value, list) {
    let found = false;
    let position = -1;
    let index = 0;
 
    while(!found && index < list.length) {
        if(list[index] == value) {
            found = true;
            position = index;
        } else {
            index += 1;
        }
    }
    return position;
}
Posted by: Guest on June-11-2020
0

JavaScript Implementation of Linear Search

Set found to false
Set position to −1
Set index to 0
while found is false and index < number of elements
    if list[index] is equal to search value
        Set found to true
        Set position to index
    else Add 1 to index
return position
Posted by: Guest on May-02-2021

Code answers related to "JavaScript Implementation of Linear Search"

Code answers related to "Javascript"

Browse Popular Code Answers by Language