Skip to content

Conversation

rstacruz
Copy link
Contributor

See #27 :) This one does NOT update README.md with documentation... I had no idea how to do that. Nonetheless they should be well documented via jsdoc.

const mapToArray = require('object-loops/map-to-array')
const map = require('object-loops/map')

mapToArray({ a: 1, b: 2, c: 3 }, n => n * n)
//=> [ 1, 4, 9 ]

map({ a: 1, b: 2, c: 3 }, n => n * n)
//=> { a: 1, b: 4, c: 9 }

These functions will be helpful in dealing with React. Like this:

const ListPeople = () => {
  people = {
    john: "John Lennon",
    ringo: "Ringo Starr"
  }

  // A regular `map()` would break things here. It needs to return an array.
  return <div>
    {mapToArray(people, (name, id) => <li id={id}>Mr. ${name}</li>)}
  </div>
}

@rstacruz
Copy link
Contributor Author

It might be worth noting that this is the same behavior of lodash/underscore's _.map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant