answer.
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
Consider a set A = {a1, . . . , an} and a collection B1, B2, . . . , Bm of subsets of A (i.e., Bi ⊆ A for each i). We say that a
Marizza181 [45]

Answer:

Explanation:

This is actually quite straight forward to solve, first lets be mindful of the explanation so with this basis we can tackle future problems.

The solution may very well may be appeared in the accompanying manner:

This solution needs to display that the set H-one can without much of a stretch confirm in polynomial-time if H is of size k and meets every one of the sets B1.....Bm .

We lessen from Vertex Cover.Consider an example of the Vertex-Cover issue chart G=(V,E) and a positive whole number k.We map it to an occurrence of the hitting set issue as follows.The set An is of vertices V.

Also we know that For each edge e has a place with E we have a set Se Consisting of two end-purposes of e.It is anything but difficult to see that a lot of vertices S is a vertex front of G iff the relating components from a hitting set in the hitting set case.

3 0
2 years ago
What three requirements are defined by the protocols used in network communications to allow message transmission across a netwo
pickupchik [31]

Answer:

"message encoding, message size and message delivery" are the correct answer for the above question.

Explanation:

The above defined are the three requirements which are defined as the protocol used in communication. These three requirements are a very essential part of communication because-

  1. Message Encoding is the first requirement, which is used to encode the message so that the hacker can not hack the communication data from the network.
  2. The second requirement is Message size which fixed the size and the number of packets used to send for the communication.
  3. The third requirements are Message delivery, for which the protocol needs to define the mechanism to overcome the loss of the data.

6 0
2 years ago
Which of the following best defines the term cross-platform application?(A) A program used to coordinate data sharing among mult
Delicious77 [7]

Answer:

D

Explanation:

An application that runs the same way on multiple operating systems is called

"cross-platform application". For example we develop one application which we are able to execute on windows, Linux without any issues then it is a cross platform application. Our code should be like that it supports multiple Operating Systems

8 0
2 years ago
Read 2 more answers
A simplified main program used to test functions is called
padilas [110]
<span>A simplified main program used to test functions is called <u><em>formula</em></u>
</span><span />
8 0
2 years ago
The ________ method is based on simple arithmetic. The process involves dividing the bits of a frame into equal segments, adding
liq [111]

Any answer choices?            


6 0
2 years ago
Other questions:
  • Computer design software requires __________________ to be used properly and successfully by architects.
    9·2 answers
  • Based on a kc value of 0.150 and the data table given, what are the equilibrium concentrations of xy, x, and y, respectively?
    9·1 answer
  • Assume that the variables gpa, deansList and studentName, have been declared and initialized. Write a statement that adds 1 to d
    13·1 answer
  • An electronics store purchased a CD player at a wholesale price of $60 and then sold it at a 40 percent discount off the origina
    13·1 answer
  • The code selection above is taken from the Color Sleuth activity you just completed. This selection would count as an abstractio
    12·1 answer
  • (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o
    10·1 answer
  • A company moves a popular website to a new web host. Which of the following will change as a result?
    15·1 answer
  • In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the mont
    14·1 answer
  • HELP 30 points and Brainliest.Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • Plz help code practice for python
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!