OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // TODO(jacobr): move into a core library or at least merge with the copy |
| 6 // in client/dom/src |
| 7 class _Lists { |
| 8 |
| 9 /** |
| 10 * Returns the index in the array [a] of the given [element], starting |
| 11 * the search at index [startIndex] to [endIndex] (exclusive). |
| 12 * Returns -1 if [element] is not found. |
| 13 */ |
| 14 static int indexOf(List a, |
| 15 Object element, |
| 16 int startIndex, |
| 17 int endIndex) { |
| 18 if (startIndex >= a.length) { |
| 19 return -1; |
| 20 } |
| 21 if (startIndex < 0) { |
| 22 startIndex = 0; |
| 23 } |
| 24 for (int i = startIndex; i < endIndex; i++) { |
| 25 if (a[i] == element) { |
| 26 return i; |
| 27 } |
| 28 } |
| 29 return -1; |
| 30 } |
| 31 |
| 32 /** |
| 33 * Returns the last index in the array [a] of the given [element], starting |
| 34 * the search at index [startIndex] to 0. |
| 35 * Returns -1 if [element] is not found. |
| 36 */ |
| 37 static int lastIndexOf(List a, Object element, int startIndex) { |
| 38 if (startIndex < 0) { |
| 39 return -1; |
| 40 } |
| 41 if (startIndex >= a.length) { |
| 42 startIndex = a.length - 1; |
| 43 } |
| 44 for (int i = startIndex; i >= 0; i--) { |
| 45 if (a[i] == element) { |
| 46 return i; |
| 47 } |
| 48 } |
| 49 return -1; |
| 50 } |
| 51 } |
OLD | NEW |