Otaku-Projects /
AngularJS-CRUD-PHP
| 1 | // Array.indexOf polyfill for IE8 |
||
| 2 | if (!Array.prototype.indexOf) { |
||
| 3 | Array.prototype.indexOf = function (searchElement, fromIndex) { |
||
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Loading history...
|
|||
| 4 | var k; |
||
| 5 | |||
| 6 | // 1. Let O be the result of calling ToObject passing |
||
| 7 | // the this value as the argument. |
||
| 8 | if (this == null) { |
||
| 9 | throw new TypeError('"this" is null or not defined'); |
||
| 10 | } |
||
| 11 | |||
| 12 | var O = Object(this); |
||
| 13 | |||
| 14 | // 2. Let lenValue be the result of calling the Get |
||
| 15 | // internal method of O with the argument "length". |
||
| 16 | // 3. Let len be ToUint32(lenValue). |
||
| 17 | var len = O.length >>> 0; |
||
| 18 | |||
| 19 | // 4. If len is 0, return -1. |
||
| 20 | if (len === 0) { |
||
| 21 | return -1; |
||
| 22 | } |
||
| 23 | |||
| 24 | // 5. If argument fromIndex was passed let n be |
||
| 25 | // ToInteger(fromIndex); else let n be 0. |
||
| 26 | var n = +fromIndex || 0; |
||
| 27 | |||
| 28 | if (Math.abs(n) === Infinity) { |
||
| 29 | n = 0; |
||
| 30 | } |
||
| 31 | |||
| 32 | // 6. If n >= len, return -1. |
||
| 33 | if (n >= len) { |
||
| 34 | return -1; |
||
| 35 | } |
||
| 36 | |||
| 37 | // 7. If n >= 0, then Let k be n. |
||
| 38 | // 8. Else, n<0, Let k be len - abs(n). |
||
| 39 | // If k is less than 0, then let k be 0. |
||
| 40 | k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
||
| 41 | |||
| 42 | // 9. Repeat, while k < len |
||
| 43 | while (k < len) { |
||
| 44 | // a. Let Pk be ToString(k). |
||
| 45 | // This is implicit for LHS operands of the in operator |
||
| 46 | // b. Let kPresent be the result of calling the |
||
| 47 | // HasProperty internal method of O with argument Pk. |
||
| 48 | // This step can be combined with c |
||
| 49 | // c. If kPresent is true, then |
||
| 50 | // i. Let elementK be the result of calling the Get |
||
| 51 | // internal method of O with the argument ToString(k). |
||
| 52 | // ii. Let same be the result of applying the |
||
| 53 | // Strict Equality Comparison Algorithm to |
||
| 54 | // searchElement and elementK. |
||
| 55 | // iii. If same is true, return k. |
||
| 56 | if (k in O && O[k] === searchElement) { |
||
| 57 | return k; |
||
| 58 | } |
||
| 59 | k++; |
||
| 60 | } |
||
| 61 | return -1; |
||
| 62 | }; |
||
| 63 | } |