heron2014 / react-todo

0 stars 0 forks source link

imperative versus declarative #5

Open heron2014 opened 8 years ago

heron2014 commented 8 years ago

Imperative code - you telling your program how to do something

var numbers = [1,2,3,4];
var total = 0;

for(var i =0; i < numbers.length; i++) {
  total += numbers[i]
}
// we explicitly say a list of things for the program to do

Declarative code - you telling your program what you want to do

var numbers = [1,2,3,4];

numbers.reduce(function (previous, current) {
  return previous + current
}, 0);