“Lineare Suche JavaScript” Code-Antworten

Lineare Suche JavaScript

function linearSearch(array, key){
  for(let i = 0; i < array.length; i++){
    if(array[i] === key) {
        return i;
    }
  }
  return -1;
}
Energetic Echidna

JavaScript -Implementierung der linearen Suche

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
Obnoxious Osprey

Ähnliche Antworten wie “Lineare Suche JavaScript”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen