--- tags: 30 天軟體工程師體驗營|2025 --- # 🏅 JS 任務 Day17 - 混合題目 ### 題目一:陣列與物件排序 * 依照物件中每個人的分數大小做排序 ``` =JavaScript const scoreAry = [ { name:"葉子", score:99 }, { name:"洧杰", score:60 }, { name:"卡斯伯", score:80 } ]; // input 輸入 callAry("正序",scoreAry) callAry("反序",scoreAry) // output // 第一筆 [ { name:"洧杰", score:60 }, { name:"卡斯伯", score:80 }, { name:"葉子", score:99 } ] // 第二筆 [ { name:"葉子", score:99 }, { name:"卡斯伯", score:80 }, { name:"洧杰", score:60 }, ] ``` ### 題目二:篩選資料 * 請篩選出第一個參數,並比對 `scoreAry2` 看有誰達到條件 ``` =JavaScript const scoreAry2 = [ { name:"葉子", score:99 }, { name:"洧杰", score:60 }, { name:"卡斯伯", score:80 } ]; // input 輸入 callAry2(80) callAry2(99) callAry2(100) // output 葉子卡斯伯分數有在80分以上 葉子分數有在99分以上 沒有人分數在100分以上 ``` ### 題目三:選出從零到指定數字範圍裡面的質數 ``` =JavaScript // input 輸入 prime(13) prime(30) prime(24) prime(44) // output 請以字串來顯示 "2,3,5,7,11" "2,3,5,7,11,13,17,19,23,29" "2,3,5,7,11,13,17,19,23" "2,3,5,7,11,13,17,19,23,29,31,37,41,43" ``` ## 回報流程 1. 將答案貼在 CodePen 並複製 CodePen 連結貼至「回報區」回報 (也可以將答案直接貼至「回報區」) ![](https://i.imgur.com/vftL5i0.png) <!--解答: 題目一: const scoreAry = [ { name: "葉子", score: 99 }, { name: "洧杰", score: 60 }, { name: "卡斯伯", score: 80 }, ]; function callAry(order, arr) { const sorted = [...arr].sort((a, b) => { return order === "正序" ? a.score - b.score : b.score - a.score; }); console.log(sorted); } 題目二: const scoreAry2 = [ { name: "葉子", score: 99 }, { name: "洧杰", score: 60 }, { name: "卡斯伯", score: 80 }, ]; function callAry2(minScore) { const filtered = scoreAry2.filter(item => item.score >= minScore); if (filtered.length === 0) { console.log(`沒有人分數在${minScore}分以上`); } else { const names = filtered.map(item => item.name).join(""); console.log(`${names}分數有在${minScore}分以上`); } } 題目三: function prime(limit) { function isPrime(n) { if (n < 2) return false; for (let i = 2; i <= (n); i++) { if (n % i === 0) return false; } return true; } const primes = []; for (let i = 2; i <= limit; i++) { if (isPrime(i)) primes.push(i); } console.log(primes.join(",")); } --> 回報區 --- | 報數 | Discord 名字 | CodePen /其他回饋 | |:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| | 1 | 4chan | [CodePen](https://codepen.io/ijuolaqc-the-looper/pen/gbbJzxr?editors=1011) | | 2 | dean | [CodePen](https://codepen.io/ch933114/pen/GggadZJ?editors=0011) | | 3 | SeanLuTW | [Codepen](https://codepen.io/sean85914/pen/oggRyMW) | | 4 | 7Lun | [Day-17 CodePen](https://codepen.io/mfyvqhsn-the-bold/pen/ByyeVrP?editors=0010) | | 5 | ying | [CodePen](https://codepen.io/Lara-Lin/pen/dPPEKGX) | | 6 | B | [CodePen](https://codepen.io/Babel777/pen/PwwvBbL) | | 7 | 登登登 | [CodePen](https://codepen.io/Duncanin/pen/GggaXKK) | |8|Saika|[Codepen](https://codepen.io/saika4501/pen/zxxQaXB?editors=0011)| |9|力文|[Codepen](https://codepen.io/liwenchiou/pen/YPPbOQz?editors=0011)| | 10 | pastor | [CodePen](https://codepen.io/peter_hung/pen/azzrKwv) | | 11 | Ariel | [CodePen](https://codepen.io/ariel0510/pen/raagqKa?editors=0011) | | 12 | RUDY | [CodePen](https://codepen.io/Rudy-crw/pen/vEEwwJm?editors=0010) | | 13 | Kath | [Codepen](https://codepen.io/JLin-the-lessful/pen/bNNyPbZ) | | 14 | Esther | [Codepen](https://codepen.io/biunpujm-the-flexboxer/pen/emmaqqb?editors=1111) | | 15 | han | [CodePen](https://codepen.io/iamHanCheng/pen/wBBbjBG?editors=0011) | |16|JHT|[Codepen](https://codepen.io/juanht/pen/GggbRrw?editors=0012)| | 17 |WAWATA|[Codepen](https://codepen.io/wa-wa-GNOHC-WA-Wa/pen/qEEGwJe)| | 18 | kelsonhouse | [CodePen](https://codepen.io/Kelson-House/pen/JooQbLX?editors=0011) | |19|蛋殼|[Codepen](https://codepen.io/weybrian/pen/pvvXNXM)| | 20 | BL | [CodePen](https://codepen.io/bonnieli1414/pen/raaEWKB?editors=0012) | | 21 | nora_zizi | [CodePen](https://codepen.io/Nora-Ch/pen/QwwXpQg?editors=1111) | | 22 | Leonard | [CodePen](https://codepen.io/hyyfjqra-the-sans/pen/EaaBvaE) | | 23 | HawkeyeLin | [Codepen](https://codepen.io/long-long/pen/QwwXqpx) | | 24 | jingle0900 | [Codepen](https://codepen.io/EvaLi0472/pen/raaErKj?editors=1011) | |25|小趴|[Codepen](https://codepen.io/papa2415/pen/JjqKNpQ)| | 26 | Chuang | [CodePen](https://codepen.io/uidoytjq-the-solid/pen/RNNzZgb?editors=0012) | | 27 | Hugh | [CodePen](https://codepen.io/Hugh-Chen/pen/OPPeGZN) | | 28 | mercury2508. | [CodePen](https://codepen.io/Mercury2508/pen/raaEZjp) | | 29 | William Hsieh | [CodePen](https://codepen.io/lsaimqxa-the-vuer/pen/gbbNGYg?editors=0012) | | 30 | yang |[codepen](https://codepen.io/Yang-J/pen/yyymdxy?editors=0012)| | 31 | oyll | [CodePen](https://codepen.io/dizzydog-rgb/pen/ByNBrev?editors=0011) | | 32 | wei_0982 | [CodePen](https://codepen.io/nico-lai/pen/ZYYgrxV) | | 33 | Jessie_Yu | [Jessie_Yu 的 Codepen](https://codepen.io/bakyfkso-the-looper/pen/MYwKZzL)| | 34 | xiaocai_97765 | [Codepen](https://codepen.io/dupre55667788/pen/pvJbaPQ?editors=0010) | 35 | ninii | [Codepen](https://codepen.io/niiniiii/pen/MYwmERE?editors=0112) | 36 | taishan_90178 | [Codepen](https://codepen.io/candy99/pen/myJBPqX?editors=0012) | 37 | ann.328 | [Codepen](https://codepen.io/yqmegupa-the-styleful/pen/dPomVex) | | 38 | 叮咚 | [Codepen](https://codepen.io/pinchieh-lin/pen/zxGbOqL) | | 39 | 叮咚 | [Codepen](https://codepen.io/RoganHsu/pen/qEdQvqj?editors=1012) | <!-- | num | user | [CodePen]() | -->