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
Need help with java project please!!
Irina18 [472]
 can do c++ and javascript but I might be able to help
send me a message
7 0
3 years ago
Read 2 more answers
What are the different options in a page layout feature ? Select three options
Sever21 [200]

Answer:

Half Center Right Left, theres four

Explanation:

5 0
3 years ago
Mary needs to choose the menu in order to place the text in a desired fashion around the image.
mixas84 [53]
Full features



Option C


hope this one help
6 0
3 years ago
Network convergence refers to using a single_______________.
CaHeK987 [17]

Answer:

Network, vendor, and bill.

Explanation:

Network convergence is a term used in communication networking that describes the productive synergy among telephone, video, and data transmission using a single network, vendor, and a bill. It enables usage of numerous devices and numerous services with single network, vendor, and bill.

Hence, in this case, it can be concluded that, Network convergence refers to using a single network, single vendor, and single bill.

7 0
3 years ago
An event or action that causes the task to start is called a
Vikentia [17]

Answer:

Trigger

Explanation:

The process through which an event or an action causes the task to start is called triggering. It is being extensively used in different subjects related to computer programming. And like we create a trigger in DBMS, to trigger some event like showing the output of some queries. And we do have the trigger used by various software as well, and which are built in various programming languages, and various platforms.

5 0
3 years ago
Other questions:
  • A______ is a picture icon that is a direct link to a file or folder
    13·1 answer
  • Adam discovers a virus on his system that is using encryption to modify itself. the virus escapes detection by signature-based a
    14·1 answer
  • The top of a ladder must extend how many feet above the surface a worker is climbing onto?
    7·1 answer
  • Define networks, marketplaces, and platforms and discuss their differences.
    15·1 answer
  • A Windows application which demands a lot of raw processing power to execute repetitive complex calculations is a good candidate
    5·1 answer
  • How do you copy and paste plz let me know
    14·2 answers
  • To rotate text in a cell select the option in the alignment grouping
    9·2 answers
  • Which of the following can computer maintenance software determine?
    6·1 answer
  • Which statement is false? Select one: a. Function printf does not care how large the array it is printing is. b. Function scanf
    9·1 answer
  • Can a 3048 hp motherboard support a i7 10700k cpu?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!