Skip to content

Commit

Permalink
revert array test
Browse files Browse the repository at this point in the history
  • Loading branch information
eWert-Online committed Aug 26, 2023
1 parent f4bc6da commit 231b306
Showing 1 changed file with 72 additions and 28 deletions.
100 changes: 72 additions & 28 deletions test/array.t/data.pi
Original file line number Diff line number Diff line change
@@ -1,35 +1,79 @@
component C {
let array = 1...1000;
use Base;

let array = 0...3;
let new_array = array <- 4;
let new_array_2 = array <- 4 <- 5 <- 6;

let merged_array = new_array @@ 5...7;
let merged_array_2 = new_array @@ 5...7 @@ [8, 9];

let merge = fn (a, b, f) -> {
let len_a = Base.Array.length(a);
if len_a == 0 {
b
let merged_record = { a: 1, b: 2 } @@ { c: 3 };
let merged_record_2 = { a: 1, b: 2 } @@ { b: 3 } @@ { y: 8 };

let nested_array = new_array <- (merged_array <- merged_record_2);
let index = 8;

let partitioned = merged_array_2 |> Array.partition(fn (item) -> {item % 2 == 0});
let even = partitioned[0];
let odd = partitioned[1];

<section>
{array}

{new_array}

{new_array_2}

{merged_array}

{merged_array_2}

{merged_record}
{merged_record_2}

{nested_array[2 + 3 * 1][index]["y"]}
{nested_array[2 + 3 * 1][index].y}

{even}

{odd}

{merged_array_2 |> Array.keep(fn (item) -> {item % 2 == 0})}

{if (merged_array_2 |> Array.find(fn (item) -> {item == 3})) {
"FOUND"
} else {
let len_b = Base.Array.length(b);
if len_b == 0 {
a
} else {
if f(a[0], b[0]) < 0 {
[a[0]] @@ merge(Base.Array.slice(a, 1, len_a), b, f)
} else {
[b[0]] @@ merge(a, Base.Array.slice(b, 1, len_b), f)
}
}
}
}
"NOT FOUND"
}}

let sort = fn (array, f) -> {
let len = Base.Array.length(array);
if len < 2 {
array
{if merged_array_2 |> Array.find(fn (item) -> {item == -10}) {
"FOUND"
} else {
let h = Base.Math.ceil(len / 2);
let first_half = array |> Base.Array.slice(0, h);
let second_half = array |> Base.Array.slice(h, len);
merge(sort(first_half, f), sort(second_half, f), f);
"NOT FOUND"
}}

{even |> Array.every(fn (item) -> {item % 2 == 0})}
{merged_array_2 |> Array.some(fn (item) -> {item % 2 == 0})}
{merged_array_2 |> Array.every(fn (item) -> {item % 2 == 0})}
{merged_array_2 |> Array.some(fn (item) -> {item < 0})}
{
Array.make(6)
|> Array.map(fn (item) -> item + 1)
|> Array.reduce(0, fn (acc, item) -> item + acc)
}

{merged_array_2 |> Array.take_until(fn item -> item == 5)}

{1...10 |> Array.slice(2, 5)}

{
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
|> Array.chunk(3)
|> Array.map(fn chunk -> Array.join(chunk, ","))
|> Array.map(fn item -> <div> {item} </div>)
}
}

sort(array, fn (a, b) -> 0)
}
{[5, 1, 2, 3, 6, 3, 4, 7] |> Array.sort(fn (a, b) -> a - b)}
</section>
}

0 comments on commit 231b306

Please sign in to comment.