Question

Can someone please help, third time I'm asking. I need a basic javascript with no push...

Can someone please help, third time I'm asking. I need a basic javascript with no push or splice command. Please don't post a picture of the code,because my vision is poor and I won't be able to see it. Also, I need breakdown of what's in HTMLand what' s in javascript. All requirements are below. Thanks for your help.

This is a 2 part assignment, but both parts can be completed in one program. Also, please follow ALL Required Programming parameters

Part 1 - Using your JSFiddle account and JavaScript you will create a program that will instantiate an integer array of size 1000. Fill each array element with a random integer between 1 and 100.

There is one function called insertIntoArray.

There are 3 arguments: argument 1 is the array; argument 2 is the index of where you are going to insert a new number; argument 3 is the number to insert.

The program should insert the new number at the index given and shift all the previous entries index up by 1. Since the array is capped at 1000, the highest element of the array will be deleted. Count the number of operations performed on the array and output this to the screen. An operation is if you assign a value or compare a value - only compare or assign operations should be counted.

Change the array size to 100 and insert into a different index in the array. State using Big O Notation your time complexity.

Required Programming parameters:

1. Your Big-O notation and justification will be written in the html section of JSFiddle.

2. Create the array in Javascript: var array = new Array(1000);

3. Create a loop to assign each array element a random value.

4. DO NOT use push or splice commands - assign elements by using = (in code)

5. When inserting you will be pushing the last value off the end of the array (everything shifts right)

6. Use a global counter to count every time you make an assignment (use an = or == operator)

Part 2 - Using your JSFiddle account and Javascript you will create a program that will instantiate an integer array of size 1000. Fill each array element with a random integer between 1 and 100. Do NOT sort the array..

There will be one function called searchArray. There will be 2 arguments: argument 1 is the array; argument 2 is the value you are searching for within the array. Each time the program compares 2 numbers you must count it as an operation (only count comparisons). Output the total number of operations. State using Big O Notation your time complexity and be prepared to justify your answer. This should be output in your actual JSFiddle

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: PART 1: Htiml Code: <div id=operations!></div><br> <div id=operation s 2 ></div><br> <div id=find></div><br> idJAVASCRIPT CODE var arraynew Array (1000) document.getElementBYId( click).onclick = {my FormSubmit () ; function() functionreturn document.getElementById (updated-array) .innerHTMT updated array 1/ 0 (1) // Count the number of operations performedOutput: Number of Operations:7018 Big O Notation Time Complexity: O1)+O)+O1)+O(1)+ O(1)+ o(1) + O(1)+O(1) +O1)+O1)+1) O(1) +OUpdate Array 92-Value of array index 0 77 = Value of array index 1 91 Value of array index 2 0-Value of array index 3 75 Valu

Copyable Code:

Html Code:

<div id="operations1"></div><br>

<div id="operations2"></div><br>

<div id="find"></div><br>

<div id="find-option"></div><br>

<div id="form-array">   

    <form>

        Index:<br>

            <input type="text" name="index" id="index_value" value="3"><br>

        Number:<br>

            <input type="text" name="number" id="number" value="0"><br><br>

    </form>      

    <input type="submit" id="click" value="Update Array"><br><br>

</div>

<div id="updated-array"></div>

JAVASCRIPT CODE:

var array = new Array(1000);

document.getElementById("click").onclick = function() {myFormSubmit()};

function myFormSubmit() { //O(1)

    var index_entered = document.getElementById("index_value").value; //O(1)

    var number_entered = document.getElementById("number").value; //O(1)

    document.getElementById('updated-array').innerHTML = InsertIntoArray(array, index_entered, number_entered); //O(1)

}

function InsertIntoArray(array, index, number) { //O(1)

   

    for(var a=0; a<array.length;a++){ // O(N) //do multiple times

       //array[a] = a;

       array[a] = Math.floor((Math.random() * 100) + 1); // O(1)  

      

    }        

   

   

    //accept user input as number

    array[index] = number; // O(1)

   

    //printing output

    var updated_array = "";

    for (i = 0; i < array.length; i++) { // O(N)

   

        updated_array += array[i] + " = Value of array index " + i + "<br>"; // O(1) //1000

    }

    return document.getElementById('updated-array').innerHTML = updated_array; // O(1)

}

// Count the number of operations performed on the array and output this to the screen.

document.getElementById('operations1').innerHTML = "Number of Operations:7018";

// Time Complexity using Big O Notation

document.getElementById('operations2').innerHTML = "Big O Notation Time Complexity: O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(n) + O(n) justifies to: O(n)";

CSS Code:

#click {

    font-size: inherit;

    color: #FFF;

    background-color: #000;

    width: 10em;

    height: 3em;

}

PART 2: Add the function into the javascript: var count-0; function SearchArray2 (array, find) for (var a-0 a<array.lengthi aOutput:l count of value= 1 2 3 Searched for 50 and found it at index: 123 Index Number 0 Update Array 73 Value of array indexCopyable Code:

var count=0;

function SearchArray2(array, find) {

    for(var a=0; a<array.length;a++){ // O(N)

       array[a] = Math.floor((Math.random() * 100) + 1); // O(1)         

    }

    for (var i=0; i < array.length; i++) {

        if (array[i] == find) {

            return ("Searched for " + find + " and found it at index: " + i);

          

        }

         count=count+1;

    }

    return (find + " Not found");

}

document.getElementById('find-option').innerHTML = SearchArray2(array, 50);

// Time Complexity using Big O Notation

document.getElementById('operations2').innerHTML = "A1 Big O Notation Time Complexity: O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(1) + O(n) + O(n) justifies to: O(n)"+count;

document.getElementById('operations2').innerHTML ="count of value="+count;

Add a comment
Know the answer?
Add Answer to:
Can someone please help, third time I'm asking. I need a basic javascript with no push...
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
  • 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....

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • I need help in C++ assignment. please add statements and i am Xcode complier user. Requested...

    I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...

  • Data Sturctuers C++ The time complexity of inserting a new element into a dynamic array is...

    Data Sturctuers C++ The time complexity of inserting a new element into a dynamic array is O(1) because you can assign a value using a[i] = x; Select one: True False Question 2 The time complexity for inserting a value into a linked list at a specific index is when is O(1) because you can just use linkedlist.set( i, val) Select one: True False Question 3 The time complexity for inserting a value into a linked list after a specific...

  • java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code...

    java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code I'll tell you what to do. Use other code as a guide.  Start with a for loop with a start of int i = 0  Set the ending point of when i is less than the length of the arr array.  Set the incrementation to increase i by 1 using the unary operator ++.  Within the loop set the arr...

  • I need help making this work correctly. I'm trying to do an array but it is...

    I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...

  • Hi I need some help on this lab. The world depends on its successfull compilation. /*...

    Hi I need some help on this lab. The world depends on its successfull compilation. /* Lab5.java Arrays, File input and methods Read the comments and insert your code where indicated. Do not add/modify any output statements */ import java.io.*; import java.util.*; public class Lab5 { public static void main (String[] args) throws Exception { final int ARRAY_MAX = 30; // "args" is the list of tokens you put after "java Project3" on command line if (args.length == 0 )...

  • Suppose we want to implement a circular queue using an array that has an initial capacity...

    Suppose we want to implement a circular queue using an array that has an initial capacity (maximum number of elements) MAX. A circular queue is like a regular queue except that elements can be enqueued or dequeued by wrapping around it. Assume we enqueue on the tail and dequeue from the head. An example circular queue with sample operations is shown below: head head tail head tail tail head Enqueue(9) a) Write a program in C that implements this circular...

  • I'm a little crunched for time and need some help with these first two questions. Thank...

    I'm a little crunched for time and need some help with these first two questions. Thank you! Question 1.) Write a Java program that reads in sequence of integers from the user until user enters a negative number and stores them in an Integer ArrayList. Once read, display a bar chart based on the values stored in the ArrayList. For example, if the user inputs 2, 5, 3, 8, 4, and -1, then your program should display the bar chart...

  • can someone please help me with this. I need to use java. Recursion Write and run...

    can someone please help me with this. I need to use java. Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...

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