{"action":"created","issue":{"url":"https://api.github.com/repos/Turfjs/turf/issues/513","repository_url":"https://api.github.com/repos/Turfjs/turf","labels_url":"https://api.github.com/repos/Turfjs/turf/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/Turfjs/turf/issues/513/comments","events_url":"https://api.github.com/repos/Turfjs/turf/issues/513/events","html_url":"https://github.com/Turfjs/turf/issues/513","id":188236133,"number":513,"title":"Callback with index in propEach and featureEach","user":{"login":"kkukielka","id":2983580,"avatar_url":"https://avatars.githubusercontent.com/u/2983580?v=3","gravatar_id":"","url":"https://api.github.com/users/kkukielka","html_url":"https://github.com/kkukielka","followers_url":"https://api.github.com/users/kkukielka/followers","following_url":"https://api.github.com/users/kkukielka/following{/other_user}","gists_url":"https://api.github.com/users/kkukielka/gists{/gist_id}","starred_url":"https://api.github.com/users/kkukielka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkukielka/subscriptions","organizations_url":"https://api.github.com/users/kkukielka/orgs","repos_url":"https://api.github.com/users/kkukielka/repos","events_url":"https://api.github.com/users/kkukielka/events{/privacy}","received_events_url":"https://api.github.com/users/kkukielka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-09T12:29:13Z","updated_at":"2016-11-09T15:47:48Z","closed_at":null,"body":"Hi,\r\n\r\nCan you add index into callback in `turf-meta` functions?\r\n\r\nNow you have:\r\n```js\r\nfunction propEach(layer, callback) {\r\n    var i;\r\n    switch (layer.type) {\r\n    case 'FeatureCollection':\r\n        for (i = 0; i < layer.features.length; i++) {\r\n            callback(layer.features[i].properties);\r\n        }\r\n        break;\r\n    case 'Feature':\r\n        callback(layer.properties);\r\n        break;\r\n    }\r\n}\r\n```\r\n\r\nBut you can change it to:\r\n\r\n```js\r\nfunction propEach(layer, callback) {\r\n    var i;\r\n    switch (layer.type) {\r\n    case 'FeatureCollection':\r\n        for (i = 0; i < layer.features.length; i++) {\r\n            callback(layer.features[i].properties, i);\r\n        }\r\n        break;\r\n    case 'Feature':\r\n        callback(layer.properties, 0);\r\n        break;\r\n    }\r\n}\r\n```\r\n\r\nSo using this function would be really **similar** (as you said in doc) to `Array.forEach` :)"},"comment":{"url":"https://api.github.com/repos/Turfjs/turf/issues/comments/259446717","html_url":"https://github.com/Turfjs/turf/issues/513#issuecomment-259446717","issue_url":"https://api.github.com/repos/Turfjs/turf/issues/513","id":259446717,"user":{"login":"DenisCarriere","id":550895,"avatar_url":"https://avatars.githubusercontent.com/u/550895?v=3","gravatar_id":"","url":"https://api.github.com/users/DenisCarriere","html_url":"https://github.com/DenisCarriere","followers_url":"https://api.github.com/users/DenisCarriere/followers","following_url":"https://api.github.com/users/DenisCarriere/following{/other_user}","gists_url":"https://api.github.com/users/DenisCarriere/gists{/gist_id}","starred_url":"https://api.github.com/users/DenisCarriere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DenisCarriere/subscriptions","organizations_url":"https://api.github.com/users/DenisCarriere/orgs","repos_url":"https://api.github.com/users/DenisCarriere/repos","events_url":"https://api.github.com/users/DenisCarriere/events{/privacy}","received_events_url":"https://api.github.com/users/DenisCarriere/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T15:47:48Z","updated_at":"2016-11-09T15:47:48Z","body":"Other alternatives in ES6 would be using `map` `filter` `reduce` functions.\r\n\r\n**Examples**\r\n```javascript\r\n// fc => GeoJSON.FeatureCollection\r\n// Loop each feature within a FeatureCollection \r\nfc.features.map(feature => feature)\r\n\r\n// Filter only features with a name property\r\nfc.features = fc.features.filter(feature => feature.properties.name)\r\n```\r\n"}}
{"actor":{"display_login":"DenisCarriere"}}