Nodejs Utililty Methods Array Search Linear

List of utility methods to do Array Search Linear

Description

The list of methods to do Array Search Linear are organized into topic(s).

Method

linearSearch(val)
Array.prototype.linearSearch = function(val){
  for (var i=0; i<this.length; i++) {
    if (this[i] === val) {
      return i;
  return -1;
};
linearSearch(val)
Array.prototype.linearSearch = function(val){
  for (var i = 0 ; i < this.length; i++) {
    if (this[i] === val)
      return i;
  return -1;
};
linearSearch(val)
Array.prototype.linearSearch = function(val){
  for (var i = 0; i < this.length; i++) {
    if(this[i] === val) {
      return i
  return -1;
Array.prototype.binarySearch = function(val){
...
linearSearch(val)
Array.prototype.linearSearch = function(val){
  var answer = this.reduce(function(prev, curr, i){
    if (curr === val) {
      prev = i;
      return prev;
    } else {
      return prev;
  }, -1);
...