UNPKG

maia-util

Version:

Utility math and music functions supporting various applications by Music Artificial Intelligence Algorithms, Inc.

41 lines (39 loc) 1.08 kB
import array_equals from './array_equals' export default function index_item_1st_doesnt_occur(arr,a){ // Tom Collins 1/2/2015. // In // a Array, Boolean, Number, or String mandatory // Out Integer // Returns the index at which the given argument a first does not occur. It // is robust in the sense that it will match arguments consisting of arrays, // strings, and booleans as well as numbers. It will not match arbitrary // objects, however (see second example in testing). var typeofa = typeof a; var instanceofarraya = a instanceof Array; var idx = -1; var i = 0; while (i < arr.length) { if (!(typeof arr[i] == typeofa) || (instanceofarraya && !(arr[i] instanceof Array))){ idx = i; i = arr.length - 1; } else{ if(instanceofarraya && arr[i] instanceof Array){ if (!array_equals(arr[i],a)){ idx = i; i = arr.length - 1; } } else{ if (!(arr[i] == a)){ idx = i; i = arr.length - 1; } } } i=i+1; } return idx; }