javascript如何将功能从命令式更改为功能式

时间:2019-07-24 03:44:36

标签: javascript functional-programming

我是函数式编程和使用angularjs开发Web应用程序的新手。我尝试将一些正式功能更改为功能。函数方法只有一个入口,只有一个返回,在函数内部应该没有副作用。但是在我的函数中,我更改了for循环的状态,所以我想我必须在下面将其分成几个块? 命令式返回true / false,并在一圈for循环中更改状态 我期望的是对功能的更改,没有其他for循环

function checkStatusOfChildTest(childList) {

            for (var i = 0; i <childList.length;i++) {
                var keys = Object.keys(childList[i]);
                if (keys.length === 1 && keys[0] === '$status') {
                    if (childList[i][keys[0]] === 'create') {
                        return true;
                    } else {
                        //just mark the status of child as delete, then remove child when save finally
                        childList[i][keys[0]] = 'delete';
                        return false;
                    }
                }
            }

            //if no status is new one
            return true;

        }

0 个答案:

没有答案
相关问题