• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15declare function print(arg:any) : string;
16function foo1() {
17    let s = 0;
18    for (let i = 1; i <= 10; i++) {
19        s += i;
20    }
21    return s;
22}
23print(foo1())
24
25let arr = new Int32Array([1, 2, 3, 4]);
26function foo2(u : Int32Array) {
27    let s = 10;
28    for (let i = 0; i < u.length; i++) {
29        for (let j = 0; j < u.length; ++j) {
30            s += u[i] * u[j];
31        }
32    }
33    return s;
34}
35print(foo2(arr))
36
37let arr2 = new Int32Array([0, 0, 0, 0]);
38function foo3(u : Int32Array, v : Int32Array) {
39    let s = 10;
40    for (let i = 0; i < u.length; ++i) {
41        for (let j = i; j < v.length; ++j) {
42            for (let k = i; k < v.length; ++k) {
43                u[i] += v[j] * v[k];
44            }
45        }
46    }
47    for (let i = 0; i < arr.length; ++i) {
48        s += u[i];
49    }
50    return s;
51}
52print(foo3(arr2, arr));