สรุป Array.slice() vs Array.filter()

ถ้าเราต้องเจองานที่รู้แน่ๆว่า จะลบ element ใด ใน Array เช่น ตัวอย่างนี้

Reducer type delete

มาดูผลลัพธ์ว่ามันต่างกันมากแค่ไหน

สรุป

Slice เขียนยากกว่า แต่มันเร็วกว่า เพราะมันไม่ต้องวนลูป sequential เพื่อกรองข้อมูล ใช้เทคนิคตัดข้อมูลซ้าย และ ขวา มาประกอบเป็นก้อนข้อมูลที่ต่างการ

Filter เขียนง่ายกว่า อ่านง่ายกว่า แต่ช้า ต้องลูป หลีกเลี่ยงไม่ได้

…..เขียนยาก ทำงานเร็ว เขียนง่าย ทำงานช้า …..

ตัวอย่างเพิ่มเติม https://jsbin.com/wodekariyo/edit?js,console

)

Teerapong Singthong 👨🏻‍💻

Written by

LINE Engineer x Software Craftsmanship

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade