* Implements `Array.find()` method that's not yet available in all browsers. * * @param {?Array } array * @param {function(T, number, !Array ):boolean} predicate * @return {?T} * @template T
(array, predicate)
| 3060 | * @template T |
| 3061 | */ |
| 3062 | function findInArray(array, predicate) { |
| 3063 | if (!array) { |
| 3064 | return null; |
| 3065 | } |
| 3066 | const len = array.length || 0; |
| 3067 | if (len > 0) { |
| 3068 | for (let i = 0; i < len; i++) { |
| 3069 | const other = array[i]; |
| 3070 | if (predicate(other, i, array)) { |
| 3071 | return other; |
| 3072 | } |
| 3073 | } |
| 3074 | } |
| 3075 | return null; |
| 3076 | } |
| 3077 | |
| 3078 | /** |
| 3079 | * Copyright 2019 The Subscribe with Google Authors. All Rights Reserved. |