1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kherson [118]
4 years ago
10

Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the ou

tput should be capitalized only if the original word was capitalized. Specifications Challenge.toCamelCase(str) given a string with dashes and underscore, convert to camel case Parameters str: String - String to be converted Return Value String - String without dashes/underscores and camel cased Examples str Return Value "the-stealth-warrior" "theStealthWarrior" "A-B-C" "ABC"

Computers and Technology
1 answer:
nata0808 [166]4 years ago
3 0

Answer:

I am writing a Python program. Let me know if you want the program in some other programming language.

def toCamelCase(str):  

   string = str.replace("-", " ").replace("_", " ")  

   string = string.split()

   if len(str) == 0:

       return str

   return string[0] + ''.join(i.capitalize() for i in string[1:])

   

print(toCamelCase("the-stealth-warrior"))

Explanation:

I will explain the code line by line. First line is the definition of  toCamelCase() method with str as an argument. str is basically a string of characters that is to be converted to camel casing in this method.

string = str.replace("-", " ").replace("_", " ") . This statement means the underscore or dash in the entire are removed. After removing the dash and underscore in the string (str), the rest of the string is stored in string variable.  

Next the string = string.split()  uses split() method that splits or breaks the rest of the string in string variable to a list of all words in this variable.

if len(str) == 0 means if the length of the input string is 0 then return str as it is.

If the length of the str string is not 0 then return string[0] + ''.join(i.capitalize() for i in string[1:])  will execute. Lets take an example of a str to show the working of this statement.

Lets say we have str = "the-stealth-warrior". Now after removal of dash in by replace() method the value stored in string variable becomes the stealth warrior. Now the split() method splits this string into list of three words the, stealth, warrior.

Next return string[0] + ''.join(i.capitalize() for i in string[1:])  has string[0] which is the word. Here join() method is used to join all the items or words in the string together.

Now i variable moves through the string from index 1 and onward and keeps capitalizing the first character of the list of every word present in string variable from that index position to the end.  capitalize() method is used for this purpose.

So this means first each first character of each word in the string starting from index position 1 to the end of the string is capitalized and then all the items/words in string are joined by join() method. This means the S of stealth and W of warrior are capitalized and joined as StealthWarrior and added to string[0] = the which returns theStealthWarrior in the output.

You might be interested in
Build a snowman
katrin [286]
°o°>
\0/
O do you like my snow man


I want you to know that I’m never leaving cuz I’m mister snow to death we’ll be freezing so come on let’s go let’s go below zero and hide from the sun
7 0
3 years ago
Ways to ask for help effectively include
Step2247 [10]

Answer:

All of these choices

Explanation:

Clarity → the quality of being coherent and intelligible.

Sincerity → the quality of being free from pretense, deceit, or hypocrisy

Open mind → Open-mindedness is receptiveness to new ideas.

8 0
3 years ago
ROM (read only memory) is used to store the essential parts of the operating system while the computer is running, as well as th
Fudgin [204]

Answer: The question is right.

Explanation: ROM (read only memory) is the type of storage in a computer that stores permanent of semipermanent data. The data that is stored in ROM may only be read, just as the name indicates, this data cannot be modified.

ROM is nonvolatile like the RAM, and even after the computer is turned off, the data in the ROM still remains.

The essential programming that is needed to start the computer is stored in the ROM.

ROM performs major the major input/output tasks and stores programs and software instructions.

8 0
3 years ago
Write a function named multi that takes in three integers, multiplies them, and then returns a statement showing the three numbe
strojnjashka [21]

I wrote my code in python 3.8.

7 0
3 years ago
Why are high-quality transformers wound with large diameter wire?      A. To lower the hysteresis losses B. To lower the magneti
Alja [10]
D.) So that they can lower the I2R losses
7 0
3 years ago
Other questions:
  • Is anyone familiar in drawing flow charts for c++ programming
    14·1 answer
  • Your computer is slowing down because you’ve started a process that is taking most of the memory and CPU resources. Which of the
    7·1 answer
  • Explain how applying different network topologies could have an impact on the security of a network
    11·1 answer
  • Search the web to discover the 10 most common user-selected passwords, and store them in an array. Design a program that prompts
    7·1 answer
  • 23
    15·1 answer
  • before Katie turns in the paper she typed she wants a peer to review it and give her feedback Katie uses her all in one printer
    10·1 answer
  • You recently started working part-time in a retail store, and are learning about the reading devices your store uses.Your store
    9·1 answer
  • CPT (Current Procedural Terminology) codes consist of 3-4 numbers representing a unique service. True False
    14·1 answer
  • after confirming the removal of a virus from a computer, how should the technician ensure and verify the full functionality of t
    7·1 answer
  • A construction-based client would like to develop an application that can analyze an image of machinery and overlay information
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!