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]
3 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]3 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
A(an)_______is built-in preset calculation. <br>formula <br> function <br>equation <br>AutoSum​
Yanka [14]

Answer:

Hello! The answer to your question is function I had the same question and got it right!

Explanation:

Hope this helped:)

3 0
2 years ago
Among object-oriented languages, one feature that varies considerably is whether the language allows multiple inheritance. C++ d
Amiraneli [1.4K]

Multiple inheritance causes Diamond problem which happens when:

Class A is parent of class B and C

Now when class D will be inherited from both Class B and C it will have all the members of class A and B which if same will confuse the compiler to import which one?

C++ solves it by using virtual keyword with them and thus telling the compiler which one to inherit.

Java has introduced the interface concept rather then allowing multiple inheritance.

4 0
3 years ago
Because one memory location can be used repeatedly with different values, you can write program instructions once and then use t
CaHeK987 [17]

Answer:

True.

Explanation:

The statement written in the question is True.We can use one memory location and use it with different values.

For example:- When we are using a loop be it for,while or do-while.The counter that we use for iteration is one and we use that counter to run the loop.We are using a single memory location and we are updating the count in that memory location many times.

for(int i=0;i<1000;i++)

{

     //body.

}

We are using i's memory location and changing it 1000 times.

3 0
3 years ago
Fix the regular expression used in the rearrange_name function so that it can match middle names, middle initials, as well as do
marysya [2.9K]

Answer:

name = re.search(r"^([\w \.-]), ([\w \.-])$", list_name)

Explanation:

Regular expression is used to simplify the mode in which items in a data structure are for. It uses wildcards as shortcuts.

The python module for regular expression is 're'. The import statement is used to get the module and the search() method of the module is used to get the one matching item while the findall() method is used to get a list of all the matching items in a data structure.

7 0
2 years ago
Define storage device with two examples? ​
Vlad [161]

Answer:

Hehe!

Explanation:

Storage Device is a technology consisting of computer components and recording media that are used to retain digital data. It is a core function and fundamental component of computers. The central processing unit of a computer is what manipulates data by performing computations.

Examples: Hard disk and Floopy Disk.

7 0
2 years ago
Read 2 more answers
Other questions:
  • You have decided to remove a recently installed feature which method can you use to remove this feature
    13·1 answer
  • You are in charge of designing a menu tree for navigating 1,250 books in a digital library. Present an argument of whether the m
    12·1 answer
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar. question 38 op
    12·2 answers
  • The "instance" relationship shows that something is an object of a ____.
    5·1 answer
  • In order to do a binary search on an array Group of answer choices you must first do a sequential search to be sure the element
    5·1 answer
  • If a computer is not working properly,the best thing to do is ________?
    5·2 answers
  • Identify tags and attributes in HTML 5
    5·1 answer
  • In Google search results, how are organic links different from sponsored links?
    5·2 answers
  • Girls question <br> who wants to go out ;p
    11·2 answers
  • Which tab on the ribbon in the folder window allows users to change how the contents of the folder are being shown?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!