1
\$\begingroup\$

Introduction

All these snakes everywhere! I've had enough, and have decided that I much prefer camels. Therefore, I want you to convert my snakes to camels for me.

Challenge

Turn any snake_case string into a camelCase string.
Capitals should be returned to lowercase before the conversion occurs.

Test Cases

In: camel_case
Out: camelCase

In: curse_these_snakes
Out: curseTheseSnakes

In: i_promise_1234_is_not_my_password
Out: iPromise1234IsNotMyPassword

In: AAAAA_BBBBB
Out: aaaaaBbbbb

Rules

As per usual, standard loophole rules apply.
This is - shortest answer wins. Leading/trailing underscores (e.g _string_) are ignored.

Current Winners (subject to change)

Esoteric Language

Me, with -1 bytes.

Standard Language

Also me, with -2 bytes.

\$\endgroup\$
  • \$\begingroup\$ What about strings starting with an underscore? eg. _a \$\endgroup\$ – IMP1 Nov 19 at 11:57
  • 1
    \$\begingroup\$ Very similar \$\endgroup\$ – Jitse Nov 19 at 12:00
  • \$\begingroup\$ Hm. My research couldn't seem to find that, so I apologise - should I remove the question? \$\endgroup\$ – Corsaka Nov 19 at 12:01
  • \$\begingroup\$ Similar but not the same in my opinion.. Here we have only snake to camel, and not tile convention at all, e.g. The first word is lower case. \$\endgroup\$ – AZTECCO Nov 19 at 16:02
2
\$\begingroup\$

Python 3, 51 bytes

lambda s:s[0].lower()+s.title().replace('_','')[1:]

Try it online!

-4 bytes thanks to ReinstateMonica

\$\endgroup\$
  • \$\begingroup\$ Unless it introduces some edge case I'm not seeing, replace is shorter \$\endgroup\$ – Reinstate Monica Nov 19 at 12:12
  • \$\begingroup\$ @ReinstateMonica yep, fair. \$\endgroup\$ – Jitse Nov 19 at 12:15
  • \$\begingroup\$ Trailing underscores are removed. In case of leading underscore next char is removed. Try it online! \$\endgroup\$ – Yuri Ginsburg Nov 20 at 12:29
  • \$\begingroup\$ @YuriGinsburg Thanks, but a leading underscore is not valid snake_case input, so there's no need to handle it. \$\endgroup\$ – Jitse Nov 20 at 12:46
  • 1
    \$\begingroup\$ @YuriGinsburg This really very much depends on how you define 'ignored'. Since this challenge is already closed as a duplicate, I will leave it as is. \$\endgroup\$ – Jitse Nov 20 at 13:30
0
\$\begingroup\$

Ruby, 39 bytes

->x{x.downcase.gsub(/_(.)/){$1.upcase}}

Try it online!

This does nothing to leading and trailing underscores.

\$\endgroup\$
  • \$\begingroup\$ Trailing underscore is removed by this code. \$\endgroup\$ – Yuri Ginsburg Nov 20 at 10:18
  • \$\begingroup\$ Is it? It's not for me. Here's a Try-It-Online where they all have trailing underscores. And they're not removed. \$\endgroup\$ – IMP1 Nov 20 at 10:21
  • \$\begingroup\$ Sorry for mistype. Leading underscores are removed. \$\endgroup\$ – Yuri Ginsburg Nov 20 at 11:43
  • \$\begingroup\$ Also capitalisation is changed in case of leading underscore. Try it online! \$\endgroup\$ – Yuri Ginsburg Nov 20 at 12:11
0
\$\begingroup\$

Gema, 28 characters

_?=@upcase{?}
?=@downcase{?}

Sample run:

bash-5.0$ gema '_?=@upcase{?};?=@downcase{?}' <<< 'i_promise_1234_is_not_my_password'
iPromise1234IsNotMyPassword

Try it online!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.