# JS 工程師養成直播班第 11 組 --- 第 5 週討論區 ###### tags: `2022 JS直播班` `秋季班` `六角學院` | 組員名單 | 報到 | | -------- | -- | | xherbruce#6825 | :heavy_check_mark: | | m_m#5493 | 請假 | | 薯餅#3581 | :heavy_check_mark: | |安o#2448|:heavy_check_mark:| |哈囉哈#5196|:heavy_check_mark:| |juri#5114|:heavy_check_mark:| |Cookie SSS#6991|:heavy_check_mark:| |ismelee#7906|:heavy_check_mark:| ### 小組討論 - 使用 discord 討論串討論本周問題點 我們使用[pair programing](https://medium.com/pm%E7%9A%84%E7%94%9F%E7%94%A2%E5%8A%9B%E5%B7%A5%E5%85%B7%E7%AE%B1/pair-programming-%E6%98%AF%E4%BB%80%E9%BA%BC-d4fffa7f0466) 方式 一人打code 所有人給邏輯想法 一起完成一起完成小組作業 - 使用 discord 語音討論  ## 問題 ### 第一題 請用[高雄市里長資訊](https://cabu4.kcg.gov.tw/KcgRegion/OpenData/%E9%87%8C%E9%95%B7%E9%80%9A%E8%A8%8A%E9%8C%84.JSON)用 Code 寫出以下需求 1. 里長男女生人數比例 2. 前鎮區有幾個里長 3. 三民區有幾個女性里長 4. 無黨籍、民主進步黨、中國國民黨各佔幾位? 5. 所有區里長人數都整理在一個物件裡 ```JavaScript import { directory } from "./diretory"; let male = 0; let female = 0; directory.forEach((element) => { if (element.性別 === "男") { male += 1; console.log(`男性里長:${male}`); } else { female += 1; console.log(`女性里長:${female}`); } }); //1. 里長男女生人數比例 let ratio = male / female; console.log(`里長男女生人數比例: ${ratio}`); //高難度寫法 // directory.forEach((element) => { // element.性別 === "男" ? (male += 1) : element.性別 === "女" ? (female += 1) : 0; // }); //2. 前鎮區有幾個里長 let num = 0; directory.forEach((item) => { if (item.區別 === "前鎮區") { num += 1; } }); console.log(`前鎮區有幾個里長: ${num}`); //3. 三民區有幾個女性里長 let femaleNum = 0; directory.forEach((item) => { if (item.區別 === "三民區" && item.性別 === "女") { femaleNum += 1; } }); console.log(`三民區有幾個女性里長: ${femaleNum}`); //4. 無黨籍、民主進步黨、c各佔幾位? // let parties = { // "無黨籍":30, // "民主進步黨":50, // "中國國民黨":79, // } let white = 0; let green = 0; let blue = 0; directory.forEach((item) => { if (item.黨籍 === "無黨籍") { white += 1; } else if (item.黨籍 === "民主進步黨") { green += 1; } else if (item.黨籍 === "中國國民黨") { blue += 1; } }); console.log(`white: ${white},green: ${green},blue: ${blue}`); //一行解 let objParty = {}; directory.forEach((x) => (objParty.hasOwnProperty(x.黨籍) ? objParty[x.黨籍]++ : (objParty[x.黨籍] = 1))); console.log(objParty); //5 所有區里長人數都整理在一個物件裡 let total = {}; directory.forEach((item) => { if (total.hasOwnProperty(item.區別)) { total[item.區別]++; } else { total[item.區別] = 1; } }); console.log(total); ``` ### 第二題 請挑選 Codewars 論壇裡面的 10 題 8kyu 來做,可各自認領一題沒挑戰過的來做。 * [8kyu Sum of positive 加總正數](https://hackmd.io/3stQkWwDTUGtCQtGwwV3hQ?view) * [8kyu Opposites Attract 異性相吸引](https://hackmd.io/wTiRA_q2TeSLTb86OfwiOw?view) * [7kyu List Filtering 過濾串列](https://hackmd.io/@bruceycyang/rJP--bAEi) * [5kyu Directions Reduction 精簡方向](https://www.codewars.com/kata/550f22f4d758534c1100025a) * [Codepen](https://codepen.io/ColdingPoTaTo/pen/mdKVmNr) * 雖然寫5kyu,但使用課堂所學足以應付 * [7kyu Love vs friendship 字母數字對照表](https://hackmd.io/@bruceycyang/S1fJvHySi) * [7kyu Filter the number 將字串中的數字篩選出來](https://hackmd.io/@bruceycyang/Byd5NYxrs) * [6kyu Count characters in your string - 記數字串中的字元](https://hackmd.io/@bruceycyang/BJAUdkzro)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up