Identify Case
Description:
We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless.
But if we don’t know the case our inputs are in, these are not very helpful.
Task:
So the task here is to implement a function (called id
in Ruby/Crystal/JavaScript/CoffeeScript and case_id
in Python/C) that takes a string, c_str
, and returns a string with the case the input is in. The possible case types are “kebab”, “camel”, and ”snake”. If none of the cases match with the input, or if there are no 'spaces' in the input (for example in snake case, spaces would be '_'s), return “none”. Inputs will only have letters (no numbers or special characters).
Some definitions
Kebab case: lowercase-words-separated-by-hyphens
Camel case: lowercaseFirstWordFollowedByCapitalizedWords
Snake case: lowercase_words_separated_by_underscores
Examples:
id(“hello-world”) #=> “kebab”
id(“hello-to-the-world”) #=> “kebab”
id(“helloWorld”) #=> “camel”
id(“helloToTheWorld”) #=> “camel”
id(“hello_world”) #=> “snake”
id(“hello_to_the_world”) #=> “snake”
id(“hello__world”) #=> “none”
id(“hello_World”) #=> “none”
id(“helloworld”) #=> “none”
id(“hello-World”) #=> “none”
Also check out my other creations — Split Without Loss, Adding Fractions, Random Integers, Implement String#transpose, Implement Array#transpose!, Arrays and Procs #1, and Arrays and Procs #2
Similar Kata:
Stats:
Created | Nov 2, 2016 |
Published | Nov 2, 2016 |
Warriors Trained | 1231 |
Total Skips | 64 |
Total Code Submissions | 3607 |
Total Times Completed | 564 |
Ruby Completions | 59 |
Crystal Completions | 7 |
Python Completions | 247 |
JavaScript Completions | 195 |
C Completions | 99 |
CoffeeScript Completions | 9 |
Total Stars | 24 |
% of votes with a positive feedback rating | 83% of 197 |
Total "Very Satisfied" Votes | 146 |
Total "Somewhat Satisfied" Votes | 34 |
Total "Not Satisfied" Votes | 17 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |