Skip to content

Instantly share code, notes, and snippets.

@alber70g
Created September 22, 2017 11:51
Show Gist options
  • Save alber70g/6c4b226959e06a33f0024bfd90cbb649 to your computer and use it in GitHub Desktop.
Save alber70g/6c4b226959e06a33f0024bfd90cbb649 to your computer and use it in GitHub Desktop.
const doubler = (input) => {
return doubler.operationsByType[typeof input](input);
};
doubler.operationsByType = {
number: (input) => input + input,
string: (input) =>
input
.split('')
.map((letter) => letter + letter)
.join(''),
function: (input) => {
input();
input();
},
object: (input) => {
Object.keys(input)
.map((key) => (input[key] = doubler(input[key])));
return input;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment