Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
Last active August 29, 2015 14:26
Show Gist options
  • Save zhangchiqing/c6af93641d880bae97b1 to your computer and use it in GitHub Desktop.
Save zhangchiqing/c6af93641d880bae97b1 to your computer and use it in GitHub Desktop.
Write a zipObject function
function zipObject() {
// write your code
}
zipObject('f')(1);
// => { f: 1 }
zipObject('method', 'url')('GET', 'https://api.github.com/users')
// => { method: 'GET', url: 'https://api.github.com/users' }
zipObject('method', 'url', 'data')('POST', 'https://api.github.com/uesrs', { foo: 'bar' });
// => { method: 'POST', url: 'https://api.github.com/users', data: { foo: 'bar' } }
zipObject('method')('GET', 'https://api.github.com/users')
// => { method: 'GET' }
zipObject('method')();
// => { 'method': undefined }
zipObject()('GET')
// => {}
zipObject()()
// => {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment