{"action":"opened","issue":{"url":"https://api.github.com/repos/bevry/sortobject/issues/4","repository_url":"https://api.github.com/repos/bevry/sortobject","labels_url":"https://api.github.com/repos/bevry/sortobject/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/bevry/sortobject/issues/4/comments","events_url":"https://api.github.com/repos/bevry/sortobject/issues/4/events","html_url":"https://github.com/bevry/sortobject/issues/4","id":156546187,"number":4,"title":"Iterations + Contribution","user":{"login":"wifiextender","id":4725121,"avatar_url":"https://avatars.githubusercontent.com/u/4725121?v=3","gravatar_id":"","url":"https://api.github.com/users/wifiextender","html_url":"https://github.com/wifiextender","followers_url":"https://api.github.com/users/wifiextender/followers","following_url":"https://api.github.com/users/wifiextender/following{/other_user}","gists_url":"https://api.github.com/users/wifiextender/gists{/gist_id}","starred_url":"https://api.github.com/users/wifiextender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wifiextender/subscriptions","organizations_url":"https://api.github.com/users/wifiextender/orgs","repos_url":"https://api.github.com/users/wifiextender/repos","events_url":"https://api.github.com/users/wifiextender/events{/privacy}","received_events_url":"https://api.github.com/users/wifiextender/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-24T16:02:17Z","updated_at":"2016-05-24T16:02:17Z","closed_at":null,"body":"Since the object/array `.length` doesn't change, why is the need to calculate the `.length` on each iteration cycle ?\r\n\r\n```javascript\r\nvar sortObject = function (obj, comparator) {\r\n\r\n    var iterArray = function(arr, toKeyVal, comparator) {\r\n        var result = toKeyVal ? {} : [],\r\n            value = null,\r\n            len = arr.length;\r\n\r\n        arr.forEach(function(elem) {\r\n            value = toKeyVal ? obj[elem] : elem;\r\n            if (value !== null && typeof value === 'object') {\r\n                value = sortObject(value, comparator);\r\n            }\r\n            if (toKeyVal) {\r\n                result[elem] = value;\r\n            } else {\r\n                result.push(value);\r\n            }\r\n        });\r\n        return result;\r\n    };\r\n\r\n    // Arrays\r\n    if ( Array.isArray(obj) ) {\r\n        return iterArray(obj, false, comparator);\r\n\r\n    }\r\n\r\n    // Objects\r\n    else {\r\n        return iterArray(Object.keys(obj).sort(), true, comparator);\r\n    }\r\n\r\n};\r\n```"}}
{"actor":{"display_login":"wifiextender"}}