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]
3 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]3 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
Transmits data as pulses of light through tiny tubes of glass Uses standard telephone lines to create a high-speed connection Co
defon

Answer:

The answer is "True".

Explanation:

To transfer data, the fiber optic wire used a high-speed data transmission medium, which includes a small glass or plastic polymers, that carry the light beam to transmit data through swift light flashes through the cable.

  • It enables the transmission of data more quickly over larger distances.
  • In this cable, the traditional cable use to provide web data transfer to cable TV, that why the given statement is true.
4 0
3 years ago
Which phrase best describes a scenario in Excel 2016?
Airida [17]

Answer:

what are the phrases?

Explanation:

6 0
3 years ago
What is the correct process for selecting an entire row in a spreadsheet?
Valentin [98]
A. Click on any cell in the row
7 0
3 years ago
This exspansion slot essentially replaced PCI and AGP slots
MrRa [10]
PCI and AGP slots have been replaced with PCI-E slot (PCI-Express). There are different types of PCI-E buses:

PCI Express 1x (250 [500] * MB/s)
PCI Express 2x (500 [1000] * MB/s)
PCI Express 4x (1000 [2000] * MB/s)
PCI Express 8x (2000 [4000] * MB/s)
PCI Express 16x (4000 [8000] * MB/s)
<span>PCI Express 32x (8000 [16000] * MB/s)

I hope that's what you meant :)</span>
4 0
3 years ago
Search the link <br><br> gKuJXd3zYDc<br><br> Subscribe I have a vid premiering soon
lawyer [7]
I will hope this helps :p
5 0
3 years ago
Other questions:
  • Among the web programming languages, css is used to define _____ of the web page
    5·1 answer
  • Create a class called Clock to represent a Clock. It should have three private instance variables: An int for the hours, an int
    15·1 answer
  • What is a flash player?
    9·2 answers
  • _________ is the process of scanning the network to find out which Internet Protocol (IP) addresses are attached to potentially
    9·1 answer
  • In Vista and Windows 7, the Appearance and Personalization option allows you to change the
    14·1 answer
  • All of the following are advantages of database-stored information, except ______________. Multiple Choice
    7·1 answer
  • Can some one help sorry I just so confused on this and I keep failing it I just need the help So choose the best answers
    12·1 answer
  • Friday Night Funkin Fans, does this count as a leak if I share it?
    13·2 answers
  • Which of the following are acceptable to share? Check all of the boxes that apply.
    13·1 answer
  • What is the minimum ethernet frame size that will not be discarded by the receiver as a runt frame?.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!