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
aleksley [76]
2 years ago
9

Have the javascript function CountingMinutes(str) take the str parameter being passed which will be two times (each properly for

matted with a colon and am or pm) separated by a hyphen and return the total number of minutes between the two times. The time will be in a 12 hour clock format. For example: if str is 9:00am-10:00am then the output should be 60. If str is 1:00pm-11:00am the output should be 1320.
function CountingMinutes(str) {
// code goes here
return str;
}
// keep this function call here
console.log(CountingMinutes(readline()));
Computers and Technology
1 answer:
jarptica [38.1K]2 years ago
5 0

Using the knowledge in computational language in Java it is possible to write a code that function as CountingMinutes:

<h3>Writing the code in Java:</h3>

function CountingMinutes(str) {

     // code goes here  

     // Declare variables for calculating difference in minutes

     // variables in JavaScript are declared with "let" keyword

     /* Build regelar expression which will match the pattern of "12houttime-12hourtime"

        and extract time or hours in numbers from it */

     let extractedTimeStringArray = str.match(/(\d+)\:(\d+)(\w+)-(\d+)\:(\d+)(\w+)/);

     // extractedTimeStringArray array will be like- ["1:00pm-11:00am", "1", "00", "pm", "11", "00", "am", index: 0, input: "1:00pm-11:00am", groups: undefined]    for str = "1:00pm-11:00am"

     // console.log('object', time)

     

     // Extract array value at 1st index for getting first time's hours (ie time before hyphen like 1:00pm in 1:00pm-11:00am )  (like 11 from 11:32am) and convert them to minutes by multiplying by 60

     let mintsOfFirstTimeFromHours = extractedTimeStringArray[1] * 60;

     // Extract array value at 2nd index for getting first time's minutes like 32 from 11:32am

     let mintsOfFirstTimeFromMints = extractedTimeStringArray[2];

     // Extract array value at 4th index for getting second time's hours (ie time after hyphen like 11:00am in 1:00pm-11:00am ) and convert them to minutes by multiplying by 60

     let mintsOfSecondTimeFromHours = extractedTimeStringArray[4] * 60;

     // Extract array value at 5th index for getting second time's minutes like 32 from 11:32am

     let mintsOfSecondTimeFromMints = extractedTimeStringArray[5];

     // if second time's 12 hour time is in pm

     if (extractedTimeStringArray[6] === "pm") {

       // Add 12 * 60 = 720 minutes for 12 hrs

         mintsOfSecondTimeFromHours += 720;

     }

     // if first time's 12 hour time is in pm

     if (extractedTimeStringArray[3] === "pm") {

        // Add 12 * 60 = 720 minutes for 12 hrs to first time

       mintsOfFirstTimeFromHours += 720;

        // Add 12 * 60 *2 = 1440 minutes for 24 hrs to second time

       mintsOfSecondTimeFromHours += 1440;

     }

     // Calculate output minutes difference between two times separated by hyphen

    str = (mintsOfSecondTimeFromHours - mintsOfFirstTimeFromHours) + (mintsOfSecondTimeFromMints - mintsOfFirstTimeFromMints);

     // return calculated minutes difference

     return str;

   }

   // keep this function call here

   // call the function and console log the result

   console.log(CountingMinutes("1:00pm-11:00am"));

   // output in console will be-  1320

See more about Java at: brainly.com/question/12975450

#SPJ1

You might be interested in
: Write a function "def countWords(string)" that returns a count of all words in an input string represented by the variable 'st
Zina [86]
We can define a word as a group of characters without a space between them. To find the words of the input string , w can use split(delimiter) which returns a list of strings which had the defined delimiter between them in the input string.

def countWords(string):
words = string.split(" ")
count = len(words)
return count

Here we set the delimiter as the space character, and returned the length of the words list. I split each step into its own line for readability, however the function could be one line:

return len(string.split())

Here, no delimiter is specified. If one isn't given, it will default to split at any whitespace, including space.

3 0
3 years ago
) The order of messages on a sequence diagram goes from _____. (Points : 6)
Alla [95]

Answer:

Top to bottom

Explanation:

A sequence diagram shows the sequence or the order in which the interaction between components takes place.

It places them in order of the occurrence of the events or interactions between the components or objects thus arranging these from top to bottom.

The sequence diagram shows the way an object in a system functions and the order it follows.

3 0
3 years ago
Several families are planning a shared car trip on scenic drives in New Hampshire's White Mountains. To minimize the possibility
Rus_ich [418]

Answer:

Following are the response to the given question:  

Explanation:

Build a spring, sink, vertices, and vertices for each car for a household. Every unit in the stream is a human. Attach the source from each vertical of a family with such a capacity line equivalent to the family size; this sets the number of members in each household. Attach every car vertices to the sink with the edge of the car's passenger belt; this assures the correct number of people for every vehicle. Connecting every vertex in your household to any vertex in your vehicle with a capacity 1 border guarantees that one family member joins a single car. The link between both the acceptable allocation of people to vehicles as well as the maximum flow inside the graph seems clear to notice.

5 0
2 years ago
Given all of the limitations of MBR, is it still relevant in current day use?
gavmur [86]

Explanation:

<em><u>MBR does have its limitations. For starters, MBR only works with disks up to 2 TB in size. MBR also only supports up to four primary partitions—if you want more, you have to make one of your primary partitions an “extended partition” and create logical partitions inside it.</u></em>

3 0
2 years ago
Can i use windows on a mac laptop??
tia_tia [17]
Yes you can. You have to buy the whatever widows processor you want to use then download it on your Mac. However you will be able to get both Mac and PC viruses.
3 0
3 years ago
Other questions:
  • What allows multiple computers to join the same network
    11·1 answer
  • divide the input array into thirds (rather than halves), recursively sort each third, and finally combine the results using a th
    15·1 answer
  • Consider the following classes: public class A { private int myNum; public A(int x) { myNum = x; } public int getNumber() { retu
    11·1 answer
  • Consider the partially-filled array named a. What does the following loop do? (cin is a Scanner object)int[] a = {1, 3, 7, 0, 0,
    6·1 answer
  • What is the promotion and advertising stage of a product or service called?
    15·1 answer
  • Now the y0utube home screen is gone
    13·2 answers
  • define the term computer hardware and its various types mentioning 5 examples of IP or devices with one diagram each​
    9·1 answer
  • Please choose odd one out please tell fast​
    12·1 answer
  • Software piracy is acceptable as it helps us obtain software cheaper or sometimes even for free.
    15·1 answer
  • What is the abuse of electronic messaging systems to indiscriminately send unsolicited bulk messages, many of which contain hoax
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!