Skip to content

Instantly share code, notes, and snippets.

@WesleyDRobinson
Last active February 22, 2019 22:26
Show Gist options
  • Save WesleyDRobinson/a9890f2437f55344d00fcc769e215bcb to your computer and use it in GitHub Desktop.
Save WesleyDRobinson/a9890f2437f55344d00fcc769e215bcb to your computer and use it in GitHub Desktop.
lowercase the first letter of every key
// 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