Last active
February 22, 2019 22:26
-
-
Save WesleyDRobinson/a9890f2437f55344d00fcc769e215bcb to your computer and use it in GitHub Desktop.
lowercase the first letter of every key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// params = (accumulator, entry, index, object), where entry = [key, value] | |
const entriesReducer = (acc, [key, value]) => { | |
const firstLetter = value.charAt(0).toLowerCase() | |
const rest = value.slice(1) | |
acc[key] = `${firstLetter}${rest}` | |
return acc | |
} | |
// accepts an object, returns an object | |
const lowerCaseAllValues = (obj) => { | |
return Object.entries(obj).reduce(reducer, {}) | |
} | |
const testCase = { | |
one: 'One', | |
two: 'TwoTwo' | |
} | |
const expected = { | |
one: 'one', | |
two: 'twoTwo' | |
} | |
const result = lowerCaseAllValues(testCase) | |
console.assert(result, expected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment