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
SCORPION-xisa [38]
2 years ago
13

Write a function string middle(string str) that returns a string containing the middle character in str if the length of str is

odd, or the two middle characters if the length is even. For example, middle ("middle") returns "dd".
Computers and Technology
1 answer:
Katen [24]2 years ago
6 0

Answer:

function getMiddle(s) {

return s.length % 2 ? s.substr(s.length / 2, 1) : s.substr((s.length / 2) - 1, 2);

}

// I/O stuff

document.getElementById("submit").addEventListener("click", function() {

input = document.getElementById("input").value;

document.getElementById("output").innerHTML = getMiddle(input);

});

Explanation:

// >>> is an unsigned right shift bitwise operator. It's equivalent to division by 2, with truncation, as long as the length of the string does not exceed the size of an integer in Javascript.

// About the ~ operator, let's rather start with the expression n & 1. This will tell you whether an integer n is odd (it's similar to a logical and, but comparing all of the bits of two numbers). The expression returns 1 if an integer is odd. It returns 0 if an integer is even.

// If n & 1 is even, the expression returns 0.

// If n & 1 is odd, the expression returns 1.

// ~n & 1 inverts those two results, providing 0 if the length of the string is odd, and 1 if the length of the sting is even. The ~ operator inverts all of the bits in an integer, so 0 would become -1, 1 would become -2, and so on (the leading bit is always the sign).

// Then you add one, and you get 0+1 (1) characters if the length of the string is odd, or 1+1 (2) characters if the length of the string is even.

You might be interested in
Text,Audio and graphic is entered into the computer using
Inessa [10]

Answer:

I think it's input, not sure tho

8 0
3 years ago
Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
soldi70 [24.7K]

Answer:

The program written in Python is as follows

Explanation:

4 0
3 years ago
Which output will be displayed by the following program?
wolverine [178]

Answer:

h

Explanation:

5 0
2 years ago
Read 2 more answers
Which of the following techniques can you not use to make the members of the std namespace available to your code? a. Code a usi
Aleksandr-060686 [28]

Answer:

b. Code an include preprocessor directives for the members

Explanation:

Namespace in programming can be defined as the declarative region which provides scope for the identifiers such as the functions, name of the types, variables, etc.

The namespaces are $\text{used to organize}$ the code into the logical groups and also used to prevent the name collision.

The ways that can be used outside the namespace $\text{can access the members}$ as :

-- the code used the fully qualifies name

-- by using the declaration to bring one of the identifier into the scope

-- by using the directive to bring all the things in the newspaper into the scope.

Thus the correct option is (b).

5 0
2 years ago
The WAN connections to your regional offices are unfortunately extremely slow for your users and they are complaining about file
Zanzabum

Answer: (B) Branch cache

Explanation:

  The branch cache is the process of cache the data from the given file and the wen server on the wide area network. In the WAN connection, the branch code is the type of functionality which basically allow the window to providing the remote user support in the network. The branch cache basically work on the two mode that are:

  • The distributed mode
  • The host mode

The branch cache is the one of the technology that intend the cache data for reducing the network traffic in the wide are network.

Therefore, Option (B) is correct.

5 0
3 years ago
Other questions:
  • Which of the following can you NOT apply for at any FLHSMV office? A. Certificate of title B. License plates C. Vehicle registra
    15·2 answers
  • If you were given a 3D microscope to use for photography, which object(s) would you most want to photograph?
    10·2 answers
  • What is the most common way for an attacker outside of the system to gain unauthorized access to the target system?
    15·1 answer
  • What two pieces of information would you need in order to measure the masses of stars in an eclipsing binary system?
    9·1 answer
  • MULTIPLE CHOICE:
    15·1 answer
  • Assume variables SimpleWriter out and int n are already declared in each case. Write a while loop that printsA. All squares less
    11·1 answer
  • Which operating system (OS) is used to run your laptop?
    15·2 answers
  • What is a simulation?
    5·2 answers
  • Question<br> 1. Who was the first to use an abacus
    6·1 answer
  • Answer any one: write a computer program:which you know.​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!