7 kyu

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”
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”
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”
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”
case_id(“hello-world”) #=> “kebab”
case_id(“hello-to-the-world”) #=> “kebab”
case_id(“helloWorld”) #=> “camel”
case_id(“helloToTheWorld”) #=> “camel”
case_id(“hello_world”) #=> “snake”
case_id(“hello_to_the_world”) #=> “snake”
case_id(“hello__world”) #=> “none”
case_id(“hello_World”) #=> “none”
case_id(“helloworld”) #=> “none”
case_id(“hello-World”) #=> “none”
case_id(“hello-world”) #=> “kebab”
case_id(“hello-to-the-world”) #=> “kebab”
case_id(“helloWorld”) #=> “camel”
case_id(“helloToTheWorld”) #=> “camel”
case_id(“hello_world”) #=> “snake”
case_id(“hello_to_the_world”) #=> “snake”
case_id(“hello__world”) #=> “none”
case_id(“hello_World”) #=> “none”
case_id(“helloworld”) #=> “none”
case_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

Strings
Regular Expressions
Fundamentals

Stats:

CreatedNov 2, 2016
PublishedNov 2, 2016
Warriors Trained1260
Total Skips64
Total Code Submissions3701
Total Times Completed576
Ruby Completions60
Crystal Completions7
Python Completions253
JavaScript Completions202
C Completions99
CoffeeScript Completions9
Total Stars24
% of votes with a positive feedback rating83% of 201
Total "Very Satisfied" Votes148
Total "Somewhat Satisfied" Votes36
Total "Not Satisfied" Votes17
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • narayanswa30663 Avatar
  • JohanWiltink Avatar
  • lilsweetcaligula Avatar
  • FArekkusu Avatar
  • farhanaditya Avatar
Ad