{"action":"created","issue":{"url":"https://api.github.com/repos/nodeschool/discussions/issues/492","labels_url":"https://api.github.com/repos/nodeschool/discussions/issues/492/labels{/name}","comments_url":"https://api.github.com/repos/nodeschool/discussions/issues/492/comments","events_url":"https://api.github.com/repos/nodeschool/discussions/issues/492/events","html_url":"https://github.com/nodeschool/discussions/issues/492","id":40645014,"number":492,"title":"Question: Is calling Array.map() more efficient than iterating through each element of the array?","user":{"login":"jkbrooks","id":129074,"avatar_url":"https://avatars.githubusercontent.com/u/129074?v=3","gravatar_id":"","url":"https://api.github.com/users/jkbrooks","html_url":"https://github.com/jkbrooks","followers_url":"https://api.github.com/users/jkbrooks/followers","following_url":"https://api.github.com/users/jkbrooks/following{/other_user}","gists_url":"https://api.github.com/users/jkbrooks/gists{/gist_id}","starred_url":"https://api.github.com/users/jkbrooks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkbrooks/subscriptions","organizations_url":"https://api.github.com/users/jkbrooks/orgs","repos_url":"https://api.github.com/users/jkbrooks/repos","events_url":"https://api.github.com/users/jkbrooks/events{/privacy}","received_events_url":"https://api.github.com/users/jkbrooks/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodeschool/discussions/labels/question","name":"question","color":"009800"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-08-19T22:37:43Z","updated_at":"2015-01-27T15:51:11Z","closed_at":"2015-01-27T15:51:11Z","body":"Shouldn't a compiler be able to recognize the two are computationally equivalent and execute them however is easiest?"},"comment":{"url":"https://api.github.com/repos/nodeschool/discussions/issues/comments/71670538","html_url":"https://github.com/nodeschool/discussions/issues/492#issuecomment-71670538","issue_url":"https://api.github.com/repos/nodeschool/discussions/issues/492","id":71670538,"user":{"login":"martinheidegger","id":914122,"avatar_url":"https://avatars.githubusercontent.com/u/914122?v=3","gravatar_id":"","url":"https://api.github.com/users/martinheidegger","html_url":"https://github.com/martinheidegger","followers_url":"https://api.github.com/users/martinheidegger/followers","following_url":"https://api.github.com/users/martinheidegger/following{/other_user}","gists_url":"https://api.github.com/users/martinheidegger/gists{/gist_id}","starred_url":"https://api.github.com/users/martinheidegger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinheidegger/subscriptions","organizations_url":"https://api.github.com/users/martinheidegger/orgs","repos_url":"https://api.github.com/users/martinheidegger/repos","events_url":"https://api.github.com/users/martinheidegger/events{/privacy}","received_events_url":"https://api.github.com/users/martinheidegger/received_events","type":"User","site_admin":false},"created_at":"2015-01-27T15:51:11Z","updated_at":"2015-01-27T15:51:11Z","body":"@timoxley explained it spot-on imho. If I could add one thing then its that `map` and `filter` methods create a new scope. Functions with small scopes generally are fairly good optimisable by the just-in-time-compiler. \r\n\r\nAside from that here are some performance tests I quickly googled\r\nhttp://jsperf.com/map-vs-for-loop-performance/6\r\nhttp://jsperf.com/eam-map-vs-for-loop\r\nhttp://jsperf.com/map-vs-for-loop-performance/14\r\n\r\nSeems like `.map` is still somewhat slower but overall it feels fairly unimportant in comparison to correct number types (keyword: `asm.js`)\r\n\r\nClosing the issue because, well, I think its answered :)"}}