Skip to content

Commit

Permalink
sort numberts
Browse files Browse the repository at this point in the history
  • Loading branch information
moshe5745 committed Oct 27, 2024
1 parent d561dc5 commit a63d42b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions priv/static/js/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ function generateNumbers() {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Update the first 6 divs with numbers between 1 and 37
// Generate and sort the first 6 numbers between 1 and 37
const firstSixNumbers = [];
for (let i = 0; i < 6; i++) {
numberDivs[i].textContent = generateRandomNumber(1, 37);
firstSixNumbers.push(generateRandomNumber(1, 37));
}
firstSixNumbers.sort((a, b) => a - b);

// Update the first 6 divs with sorted numbers
for (let i = 0; i < 6; i++) {
numberDivs[i].textContent = firstSixNumbers[i];
}

// Update the 7th div with a number between 1 and 7
numberDivs[6].textContent = generateRandomNumber(1, 7);
}

document.addEventListener("DOMContentLoaded", function (event) {
document.addEventListener("DOMContentLoaded", function () {
document
.getElementById("refreshButton")
.addEventListener("click", generateNumbers);
Expand Down
3 changes: 3 additions & 0 deletions src/api/numbers.gleam
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gleam/int
import gleam/json.{int}
import gleam/list
import wisp
Expand All @@ -7,6 +8,8 @@ pub fn api_numbers() {
list.range(1, 37)
|> list.shuffle
|> list.take(6)
|> list.sort(by: int.compare)

let assert Ok(strong_number) =
list.range(1, 7)
|> list.shuffle
Expand Down
2 changes: 2 additions & 0 deletions src/api/numbers_html.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub fn api_numbers_html() {
list.range(1, 37)
|> list.shuffle
|> list.take(6)
|> list.sort(by: int.compare)

let assert Ok(strong_number) =
list.range(1, 7)
|> list.shuffle
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ssr.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub fn ssr_page() {
list.range(1, 37)
|> list.shuffle
|> list.take(6)
|> list.sort(by: int.compare)

let assert Ok(strong_number) =
list.range(1, 7)
|> list.shuffle
Expand Down

0 comments on commit a63d42b

Please sign in to comment.