[Day 4] 2018 Year In Review In 30 Days — Functional Programming

Chai Phonbopit
Jan 4 · 3 min read

Day 4: Functional Programming


สิ่งที่ผมได้เรียนรู้คือ

แบบ Imperative คือ บอกว่าทำอย่างไร

let data = [1, 2, 3, 4]
let result = []for (let i = 0; i < data.length; i++) {
  result.push(data[i] * 2)
}console.log(result) // [2, 4, 6, 8]

ส่วนแบบ Declarative ก็จะเป็นบอกว่าจะทำอะไร

let data = [1, 2, 3, 4]const double = value => value * 2const result = data.map(double)console.log(result) // [2, 4, 6, 8]
{a, b} = {"Ahoy", 5555}

สุดท้าย

Devahoy

Learn and share about technologies that power the world, read more at https://devahoy.com

Chai Phonbopit

Written by

[**MOVE TO MY OWN BLOG] I make web stuff with JavaScript (Node & React), Blogger at https://devahoy.com

Devahoy

Devahoy

Learn and share about technologies that power the world, read more at https://devahoy.com