owned this note
owned this note
Published
Linked with GitHub
---
tags: 30 天軟體工程師體驗營|2025
---
# 🏅 JS 任務 Day18 - 混合題目 II
### 大樂透選號
* 彩球共 49 顆,分別是 1~49 號
* 新規則:執行 `lotto` 函式會開兩組號碼,兩組號碼不可重複
``` =JavaScript
// input 輸入
lotto()
lotto()
// output 下方為範例隨機選號
// 第一筆
第一組號碼:3,44,11,13,22,49,特別號是 8 號
第二組號碼:1,22,33,45,23,7,特別號是 12 號
// 第二筆
第一組號碼:4,5,6,7,8,9,特別號是 11 號
第二組號碼:30,33,35,37,38,42,特別號是 49 號
```
## 回報流程
1. 將答案貼在 CodePen 並複製 CodePen 連結貼至「回報區」回報
(也可以將答案直接貼至「回報區」)

<!--解答:
function lotto() {
const balls = Array.from({ length: 49 }, (_, i) => i + 1);
// 洗牌函式 - Fisher-Yates
function shuffle(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
// 抽取一組號碼(6 顆 + 特別號)
function drawGroup(pool) {
const shuffled = shuffle([...pool]);
const normalNums = shuffled.slice(0, 6).sort((a, b) => a - b);
const special = shuffled[6];
return { normalNums, special, used: [...normalNums, special] };
}
// 第一次抽號
const group1 = drawGroup(balls);
// 第二組需從排除第一組已用號碼的球池中抽
const remainingBalls = balls.filter(n => !group1.used.includes(n));
const group2 = drawGroup(remainingBalls);
-->
回報區
---
| 報數 | Discord 名字 | CodePen /其他回饋 |
|:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:|
| 1 | dean | [CodePen](https://codepen.io/ch933114/pen/xbboJMp?editors=0011) |
| 2 | han | [CodePen](https://codepen.io/iamHanCheng/pen/emmwLmE?editors=0011) |
| 3 | 4chan | [CodePen](https://codepen.io/ijuolaqc-the-looper/pen/yyydEmm?editors=1011) |
| 4 | ying | [CodePen](https://codepen.io/Lara-Lin/pen/myyZjmj) |
|5|小趴|[Codepen](https://codepen.io/papa2415/pen/vYwKJBr)|
| 6|JHT|[Codepen](https://codepen.io/juanht/pen/dPPBqpa?editors=0012)|
| 7 | RUDY | [CodePen](https://codepen.io/Rudy-crw/pen/RNNzObv?editors=0011) |
| 8 | 7Lun | [Day18-CodePen](https://codepen.io/mfyvqhsn-the-bold/pen/QwwXYBZ?editors=0011) |
| 9 | B | [CodePen](https://codepen.io/Babel777/pen/dPPBBem) |
| 10 | Ariel | [CodePen](https://codepen.io/ariel0510/pen/azzgrYb?editors=0012) |
| 11 | Hugh | [CodePen](https://codepen.io/Hugh-Chen/pen/azzeoXv?editors=1011) |
| 12 | kelsonhouse | [Codepen](https://codepen.io/Kelson-House/pen/vEEqzEP?editors=0011) |
| 13 | 力文 | [Codepen](https://codepen.io/liwenchiou/pen/bNNXGyb?editors=0011) |
| 14 | Chuang | [CodePen](https://codepen.io/uidoytjq-the-solid/pen/MYYNWQK?editors=0012) |
| 15 |蛋殼|[Codepen](https://codepen.io/weybrian/pen/zxxgvWN) |
| 16 |HawkeyeLin|[Codepen](https://codepen.io/long-long/pen/vEEogLe)|
| 17 |jingle0900|[Codepen](https://codepen.io/EvaLi0472/pen/RNNXQwP?editors=1011)|
| 18 |Leonard|[Codepen](https://codepen.io/hyyfjqra-the-sans/pen/azOobQp)|
| 19 | wei_0982 | [CodePen](https://codepen.io/nico-lai/pen/LEVPRJg) |
| 20 | Jessie_Yu | [Jessie_Yu 的 Codepen](https://codepen.io/bakyfkso-the-looper/pen/ByNjEPw)|
| 21 | ninii | [CodePen](https://codepen.io/niiniiii/pen/raVmdVv?editors=1111) |
| 22 |taishan_90178 | [CodePen](https://codepen.io/candy99/pen/NPqaNXo?editors=0012) |
<!--
| num | user | [CodePen]() |
-->