+ 5
[SOLVED] How to control the range used by map() function
This code was supposed to format some string into snake_case and camelCase. Recently I learned that I was making the code to generate a PascalCase rather than camelCase result. My question is, how do I make the call to map() at line 15 to ignore the first element, and to only capitalize first letter of the second to the last element. * Illustration: I want this ... [ "hello", "world" ] becomes "helloWorld" (camelCase) But I currently have ... [ "hello", "world" ] becomes "HelloWord" (PascalCase) https://code.sololearn.com/cejMEuzcVfhW/?ref=app Thank you in advance 🙏
3 odpowiedzi
+ 7
Just a thought, can't you just do something like this with the output..
Like,
str = HelloWorld
firstChar(str).toLowerCase + str.substring(1)
___
Or if you want to maintain a one-liner .mapIndexed can help you in what you want to achieve.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-indexed.html
Sample code
https://code.sololearn.com/cyJ52vWsgBaK/?ref=app
+ 2
Emily
Thank you so much 🙏
+ 1
Ipang Glad it helped 🙏