Skip to content

Instantly share code, notes, and snippets.

@danielantelo
Created July 24, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielantelo/48908d51db19091c9a68a9c48fd938cb to your computer and use it in GitHub Desktop.
Save danielantelo/48908d51db19091c9a68a9c48fd938cb to your computer and use it in GitHub Desktop.
Javascript data transformer exercise

Javascript data transformer exercise

Write a function that would take this sample data:

[
    { banana: 'fruit' },
    { apple: 'fruit' },
    { carrot: 'vegetable' }
]

and generate this data:

{
    fruit: [ 'banana', 'apple' ],
    vegetable: 'carrot'
}
@danielantelo
Copy link
Author

const input = [
    { banana: 'fruit' },
    { apple: 'fruit' },
    { carrot: 'vegetable' }
];

const actual = transform(input);
const expected = {
    fruit: [ 'banana', 'apple' ],
    vegetable: 'carrot'
};
const isTestComplete = JSON.stringify(actual) === JSON.stringify(expected);
console.log(isTestComplete);

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