Commit e856cd47 authored by David Runger's avatar David Runger

angularjs: simplify clearCompleted method

* Remove unused `completeTodos` variable
* use `Array#filter` instead of `Array#forEach`
parent 44053122
...@@ -36,14 +36,8 @@ angular.module('todomvc') ...@@ -36,14 +36,8 @@ angular.module('todomvc')
clearCompleted: function () { clearCompleted: function () {
var originalTodos = store.todos.slice(0); var originalTodos = store.todos.slice(0);
var completeTodos = []; var incompleteTodos = store.todos.filter(function (todo) {
var incompleteTodos = []; return !todo.completed;
store.todos.forEach(function (todo) {
if (todo.completed) {
completeTodos.push(todo);
} else {
incompleteTodos.push(todo);
}
}); });
angular.copy(incompleteTodos, store.todos); angular.copy(incompleteTodos, store.todos);
...@@ -112,14 +106,8 @@ angular.module('todomvc') ...@@ -112,14 +106,8 @@ angular.module('todomvc')
clearCompleted: function () { clearCompleted: function () {
var deferred = $q.defer(); var deferred = $q.defer();
var completeTodos = []; var incompleteTodos = store.todos.filter(function (todo) {
var incompleteTodos = []; return !todo.completed;
store.todos.forEach(function (todo) {
if (todo.completed) {
completeTodos.push(todo);
} else {
incompleteTodos.push(todo);
}
}); });
angular.copy(incompleteTodos, store.todos); angular.copy(incompleteTodos, store.todos);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment