Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

linear search algorithm

const linearSearch = (arr, item) => {
  for (const i in arr) {
    if (arr[i] === item) return +i;
  }
  return -1;
};
Source by www.30secondsofcode.org #
 
PREVIOUS NEXT
Tagged: #linear #search #algorithm
ADD COMMENT
Topic
Name
5+9 =