Question

JavaScript Can someone please help me with a solution to this THNX ! Given a list...

JavaScript Can someone please help me with a solution to this THNX !

Given a list of numbers and a number B, return whether any two numbers from the list add up to B.
0 0
Add a comment Improve this question Transcribed image text
Answer #1


var twoNumSumFromList = function (list, B) {
    var num = [];

    for (var i = 0; i < list.length; i++) {
        for (var j = i + 1; j < list.length; j++) {
            if (list[i] + list[j] === B) {
               num.push(i);
               num.push(j);
            }
        }
    }
    return num;
}
console.log(twoNumSumFromList([8,15, 2, 1,5,7], 10));

// OutPut
//[ 0, 2 ]

Add a comment
Know the answer?
Add Answer to:
JavaScript Can someone please help me with a solution to this THNX ! Given a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IT Review    JAVASCRIPT (Can someone please help me answer the below questions. It would be nice...

    IT Review    JAVASCRIPT (Can someone please help me answer the below questions. It would be nice if you add comments explaining what you are doing? If unable to add comments the answer would be fantastic. Thank you. Given the following function definition: function percent(x) {      return x / 100; } Which of the following statements correctly calls the percent function: percent(10); percent: 10; percent(); percent = 10; Indicate whether each of the following evaluates to true or false, given...

  • could someone help me make a linked list in javascript, that has methods of inserting, updating...

    could someone help me make a linked list in javascript, that has methods of inserting, updating element by index, deleting by index, obtaining all the elements, obtaining elements by index, I would be very grateful to you to help me :)

  • Can someone please help me with this javascript - Javascript - do at least 10 of...

    Can someone please help me with this javascript - Javascript - do at least 10 of the following questions below ----------------------------------------------------------------------------------- Create an HTML file that takes in input and carries out of the following functions and manipulates the DOM to show the outcome. Please put the question itself as a comment above each answer. Use either JavaScript, jQuery, or both (but know the difference!). ----------------------------------------------------------------------------------- 1. Fibonacci Define function: fib(n) Return the nth number in the fibonacci sequence. 2....

  • Please help as soon as you can Thnx! // ==== Callbacks ==== /* Step 1: Create...

    Please help as soon as you can Thnx! // ==== Callbacks ==== /* Step 1: Create a higher-order function * Create a higher-order function named consume with 3 parameters: a, b and cb * The first two parameters can take any argument (we can pass any value as argument) * The last parameter accepts a callback * The consume function should return the invocation of cb, passing a and b into cb as arguments */ /* Step 2: Create several...

  • Can someone please help me step by step with this question? Given a diprotic acid, H2A,...

    Can someone please help me step by step with this question? Given a diprotic acid, H2A, with two ionization constants of K = 2.74x 10^-4 and Ka2 = 5.24x 10-11, calculate the pH and molar concentrations of H2A, HA^-, and A^2- for each of the solutions below. (a) a 0.143 M solution of H2A (b) a 0.143 M solution of NaHA (c) a 0.143 M solution of Na2A

  • Can someone please help me with this and explain how they know stability? List the following...

    Can someone please help me with this and explain how they know stability? List the following radicals in order of increasing stability.

  • Can someone please help me with these questions? There is one example given. The solution should...

    Can someone please help me with these questions? There is one example given. The solution should be like that. Necessary lines of codes which can run in dr.Racket. thank you!! Here is an example of using the llisting package to display code. Check the preamble to see where this is imported and set up. After that you will see a sample interaction from the DrRacket console to show how this function could be tested. You should provide similar listings and...

  • Can someone please help me? An experiment calls for 50ml of a 0.50 m aqueous solution...

    Can someone please help me? An experiment calls for 50ml of a 0.50 m aqueous solution of sodium hydrogen carbonate (sodium bicarbonate, or baking soda) work with your team to describe the steps you would use in order to make up such a solution, such that, you have none left over?

  • Can someone please help me solve the following database management question a - d please help...

    Can someone please help me solve the following database management question a - d please help uestion-4 The relational database schema of Question-3 is reproduced here. COURSE (NUMBER, TITLE, ENROLLED) RANK-1 (CNUMBER, R1-SSN) RANK-2 (CNUMBER, R2-SSN) TALLEST (CNUMBER, TALL-SSN) STUDENT (SSN, NAME, MAJOR, SEX, GPA) Formulate the following queries in soL. (30] (a) List the course numbers in which "Jack Hernandez" is the first ranked student. You are not allowed to use any JOIN operation and your answer must be...

  • Can someone please help me with this. a) give an arrangement why, for a given curvature,...

    Can someone please help me with this. a) give an arrangement why, for a given curvature, the stress should not depend on the length of the bone b) from the equation O=Y(r/R) estimate the strain inside a bone with a radius r and curvature 1/R

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT