--- tags: Mentocamp3 刷題讀書會 --- # 2024/02/20(二) 每週 21:00 Codewars 刷題 ## 題目 - 主要:[Codewars_7kyu Remove the minimum](https://www.codewars.com/kata/563cf89eb4747c5fb100001b/train/python) - 次要:[LeetCode] 這次Codewars題目稍難,先不出Leetcode > ## 會後Keynote (大家有用到的方法) > ### Python > - list.copy() or a[:] 複製陣列 https://docs.python.org/zh-tw/3/tutorial/datastructures.html > - remove() or pop() 移除陣列元素 https://www.w3schools.com/python/python_lists_remove.asp > - if len(my_list) == 0 or if not my_lis 判斷空陣列 > ### Javascript > - Math.min() 找最小值 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/min > - array.indexOf 找出查找元素的第一個被找到之位置 https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf > - slice() 回傳一個新陣列物件,為原陣列選擇之 begin 至 end(不含end) https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/slice > - splice() 刪除或加入新元素 https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/splice > - condition ? exprIfTrue : exprIfFalse 條件(三元)運算子可用來當作 if 的簡潔寫法. > - https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/Conditional_operator > - https://ithelp.ithome.com.tw/articles/10243261 (Duck補充) - 補充更簡潔的解法,是融合大家分享討論的解法成果: ```javascript function removeSmallest(numbers) { // 使用三元運算簡化if/else,判斷長度是否為空,如為空就返回空陣列 return numbers.length ? // 不需複製一份陣列,直接取出要的起始位置 // 使用展開願算子將兩陣列合併 [ ...numbers.slice(0, numbers.indexOf(Math.min(...numbers))), ...numbers.slice(numbers.indexOf(Math.min(...numbers)) + 1) ] : []; } ``` ## 回報格式 - 請 Fork 此 Replit 連結,進行程式碼解題,完成後將連結貼至「解題分享區」來與大家交流做法。 - Python: https://replit.com/@AnnaChu1/Codewars-Remove-the-minimum#main.py - JS: https://replit.com/@AnnaChu1/Codewars-Remove-the-minimumjs#index.js - 一定要Fork到自己帳號底下,否則我印象中程式碼會不見。 (Fork過程有錯誤或不懂的,可以再讓我知道喔!)   解題分享區 --- #### 讀書會議流程: 1. 題目說明 2. 題目解析 4. 成員分享解題思路 5. 問題與討論 #### 回報區 : <No.1> Anna Replit:https://replit.com/@AnnaChu1/Codewars-Remove-the-minimum#main.py <No.2> Jay Replit:https://replit.com/@kred110396/Codewars-Remove-the-minimum#main.py <No.3> Alvin Replit:https://replit.com/@yangalvin207/Codewars-Remove-the-minimum20240220#main.py <No.4> bing_jun Replit:https://replit.com/@PingJun-You/Codewars-Remove-the-minimumbing#main.py Replit:https://replit.com/@PingJun-You/Codewars-Remove-the-minimumjsbing#index.js <No.5> Ally Replit:https://replit.com/@a2623212/Codewars-Remove-the-minimumjs <No.6> 宗承 Replit:https://replit.com/@love970120/b71-1?v=1#index.js <No.6> 阿媜 Replit:https://replit.com/@selena60635/Codewars-Remove-the-minimumjs#index.js ...請依序貼上
×
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