{"action":"created","issue":{"url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/7535","repository_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp","labels_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/7535/labels{/name}","comments_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/7535/comments","events_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/7535/events","html_url":"https://github.com/FreeCodeCamp/FreeCodeCamp/issues/7535","id":140515939,"number":7535,"title":"\"Where do I belong\" fails the final test even though my result is correct with the for-in loop","user":{"login":"Scoodood","id":15989924,"avatar_url":"https://avatars.githubusercontent.com/u/15989924?v=3","gravatar_id":"","url":"https://api.github.com/users/Scoodood","html_url":"https://github.com/Scoodood","followers_url":"https://api.github.com/users/Scoodood/followers","following_url":"https://api.github.com/users/Scoodood/following{/other_user}","gists_url":"https://api.github.com/users/Scoodood/gists{/gist_id}","starred_url":"https://api.github.com/users/Scoodood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scoodood/subscriptions","organizations_url":"https://api.github.com/users/Scoodood/orgs","repos_url":"https://api.github.com/users/Scoodood/repos","events_url":"https://api.github.com/users/Scoodood/events{/privacy}","received_events_url":"https://api.github.com/users/Scoodood/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-13T18:57:57Z","updated_at":"2016-03-13T22:18:26Z","closed_at":null,"body":"\r\n\r\n#### Issue Description\r\n* When Issue Happens: Every time I run my code with the for-in loop\r\n* Steps To Reproduce: See my code here at [Where do I belong](http://www.freecodecamp.com/challenges/where-do-i-belong#?solution=function%20where(arr%2C%20num)%20%7B%0A%20%20%2F%2F%20Find%20my%20place%20in%20this%20sorted%20array.%0A%20%20var%20temp%20%3D%20arr.sort(function(a%2Cb)%20%7B%20%0A%20%20%20%20return%20a-b%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20%2F%2F%20it%20will%20fail%20the%20test%20if%20I%20replace%20the%20for-loop%20with%0A%20%20%2F%2F%20the%20for-in%20loop%20even%20though%20the%20result%20is%20correct%0A%20%20%2F%2F%0A%20%20%2F%2F%20for%20(var%20i%20in%20temp)%20%7B%0A%20%20for%20(var%20i%3D0%3B%20i%3Ctemp.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if%20(temp%5Bi%5D%20%3E%3D%20num)%0A%20%20%20%20%20%20return%20i%3B%0A%20%20%7D%0A%20%20return%20arr.length%3B%0A%7D%0A%0Awhere(%5B10%2C%2020%2C%2030%2C%2040%2C%2050%5D%2C%2035)%3B%0A%0A). Comment out the regular for-loop and uncomment the for-in loop, then run the test.\r\n\r\n#### Browser Information\r\n* Browser Name, Version: Google Chrome Version 48.0.2564.116 (64-bit)\r\n* Operating System: OSX 10.10.5 (Yosemite)\r\n"},"comment":{"url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/comments/196066206","html_url":"https://github.com/FreeCodeCamp/FreeCodeCamp/issues/7535#issuecomment-196066206","issue_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/7535","id":196066206,"user":{"login":"raisedadead","id":1884376,"avatar_url":"https://avatars.githubusercontent.com/u/1884376?v=3","gravatar_id":"","url":"https://api.github.com/users/raisedadead","html_url":"https://github.com/raisedadead","followers_url":"https://api.github.com/users/raisedadead/followers","following_url":"https://api.github.com/users/raisedadead/following{/other_user}","gists_url":"https://api.github.com/users/raisedadead/gists{/gist_id}","starred_url":"https://api.github.com/users/raisedadead/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raisedadead/subscriptions","organizations_url":"https://api.github.com/users/raisedadead/orgs","repos_url":"https://api.github.com/users/raisedadead/repos","events_url":"https://api.github.com/users/raisedadead/events{/privacy}","received_events_url":"https://api.github.com/users/raisedadead/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T22:18:26Z","updated_at":"2016-03-13T22:18:26Z","body":"@Scoodood Usually we do not provide code help in Github issues.\r\nBut since this can be considered a bug, by others.\r\n\r\nI would like to add some thought for anyone looking into this.\r\n> The for-in statement by itself is not a \"bad practice\", however it can be mis-used, for example, to iterate over arrays or array-like objects.\r\n\r\n> The purpose of the for-in statement is to enumerate over object properties. This statement will go up in the prototype chain, also enumerating over inherited properties, a thing that sometimes is not desired.\r\n\r\nrefering a [stackoverflow discussion](http://stackoverflow.com/a/500531) and a [following answer](http://stackoverflow.com/a/4261096)\r\n\r\nYou would want to look at the [MDN Documenation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) as well which confirms this notion.\r\n\r\nIMHO I do not mean to say that you couldn't use `for...in` but its kind of a practice that you shouldn't, in context of arrays.\r\n\r\n\r\nKeeping this open for opinion from others."}}