• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:arrayfindlast
18 * @tc.desc:test Array.findLast and Array.findLastIndex
19 * @tc.type: FUNC
20 * @tc.require: issueI7LP2E
21 */
22
23var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
24var result = -1;
25result = arr.findLast((element, index, array) => {
26    array.length = 5;
27    return (element == 5);
28});
29print(result);
30result = arr.findLast((element) => {
31    return element > 2;
32});
33print(result);
34
35result = arr.findLastIndex((element, index, array) => {
36    if (array.length == 5) {
37        array.push(100);
38    }
39    return (element == 100);
40});
41print(result);
42result = arr.findLastIndex((element, index, array) => {
43    return (element == 100);
44});
45print(result);
46
47var arr2 = new Array(1025);
48result = arr2.findLast((element, index, array) => {
49    return (element == undefined);
50});
51print(result);
52
53result = arr2.findLastIndex((element, index, array) => {
54    return (element == undefined);
55});
56print(result);
57
58result = arr2.findLastIndex((element, index, array) => {
59    array[5] = 100;
60    return (element == 100);
61});
62print(result);