• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device 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
16declare function print(str:any):string;
17var arrayIterator = ['fifth', 'sixth', 666];
18print(arrayIterator[0]);
19print(arrayIterator[1]);
20print(arrayIterator[2]);
21
22class Index {
23    currentArrays: number[][] = [
24        [0, 0, 0, 0],
25        [0, 0, 0, 0],
26        [0, 0, 0, 0],
27        [0, 0, 0, 0]
28      ]
29
30    changeCurretArrays() {
31        let newArrays = [
32            [0, 0, 0, 0],
33            [0, 0, 0, 0],
34            [0, 0, 0, 0],
35            [0, 0, 0, 0]
36        ]
37
38        for (let j = 0; j < 4; j++) {
39            for (let i = 0; i < 4; i++) {
40                newArrays[j][i] = this.currentArrays[j][i] + 1;
41            }
42        }
43        return newArrays;
44    }
45
46    computeScore(array) {
47        let total = 0;
48        for (let j = 0; j < 4; j++) {
49            for (let i = 0; i < 4; i++) {
50                total  += array[j][i];
51            }
52        }
53        return total;
54    }
55
56    run() {
57        let newArray = this.changeCurretArrays();
58        print(this.computeScore(newArray));
59        print(this.computeScore(this.currentArrays));
60        this.currentArrays = newArray;
61    }
62}
63
64let index = new Index;
65for (let i = 0; i < 3; i++) {
66    index.run();
67}