Ruby Array with Range : Note
- by NAzT
กำลังสงสัยว่า
ใน ruby a[0..n] ทำไมมันถึงไม่เหมือนกับ a[0,n] ครับ มันควรจะเหมือนกันไม่ใช่หรอครับ เพราะไปเขียน Merge Sort แล้ว มันให้ผลไม่เหมือนกันเกิด Infinite Loop เลยทีเดียว พอเปิดหนังสือดู อ้าว… เฮ้ย เจ้าตัว operator [ ] ของ array มันก็ให้ผลเหมือนกันนี่หว่า return เหมือนกันเลย หลังจากนั้นก็ลองไปเทสแยกดู ตอนแรก a[0,3] กับ a[0..3] มันเท่ากัน ก็เลย งงว่า มันก็เท่ากันนี่หว่า แต่ลองเช็คอีกทีว่าถ้าเป็น 0,0 มันจะ return อะไร แล้วก็โป๊ะเชะ
ที่มันไม่เท่าเพราะ a=["a","b","c","d"] แล้ว >> a[0..0] => ["a"] ส่วน >> a[0,0] => []
เฮ่อแบบนี้ก็ต้องใช้ a[x,y] เพราะมันจะ return [] มาได้ทำให้หลุดจาก recursion
Related Blogs
- Aries 202007 Black Side Step Bar | Center Bestsellers cheaper from …
- [polls] What sort of Christian Nation should Sarah Palin's America …
- The Olive Garden's cooking school is real … sort of | Latest Buzz
- Nintendo Declares War On Apple [Blockquote] | Hirdyz Emporium
- Freedom Central – Freedom Central
- The Conrad Black Style of Doing Hard Time / Chicago News Cooperative
- Successful People Start Fast and Finish Strong | Bud Bilanich
- Opera Finds Flash Unappetizing For Web Video [Blockquote] | Gadget …
- How to Do a Mail Merge « Imogene Braggs
- Cricket Blog – Pietersen to return home
- Opera Finds Flash Unappetizing For Web Video [Blockquote]
- Ruby 1.9 Encodings: A Primer and the Solution for Rails « Katz Got …
- Infinite Scroller 2
- Infinite Scroller 2 | XDGames.net
- Adam Lambert talks makeup and style on Jonathan Ross @ Unreality TV
- Opera Finds Flash Unappetizing For Web Video [Blockquote]
- Araxis Merge Professional 2010 (Build 3829) | s?ahuj rapidshare warez
- Denard Span / Span bounced back from a rough 0-for-8 performance …
- How do I get started developing Ruby Web applications …
- Sort Files Like A Master With The Linux Sort Command (Bash)
เรื่องที่เกี่ยวข้อง