Which of the following replacement code fragments will fix the code below?
console.log(square);
console.log(square(5));
var square = function(n) { return n * n; }
A.)
alert(square);
alert(square(5));
var square = function(n) { return n * n; }
B.)
console.log(square);
console.log(square(5));
var function square = function(n) { return n * n; }
C.)
console.log(square);
console.log(square(5));
function square = function(n) { return n * n; }
D.)
console.log(square);
console.log(square(5));
function square(n) { return n * n; }
D.)
console.log(square);
console.log(square(5));
function square(n) { return n * n; }
it should be a function
Which of the following replacement code fragments will fix the code below? console.log(square); console.log(square(5)); var square...
What would the result be if you ran the following code: function makeAdder(x) { return function(y) { return x + y; }; } var add8 = makeAdder(8); var add12 = makeAdder(12); console.log(add8(4)); console.log(add12(5));
1. var s = "A red boat"; var a = s.split(" "); what is the value of a? var b = [9, 3, 2, 1, 3, 7]; var c = b.slice(2, 5); What is the value of c? var d = c.concat(a); alert(d.join("**")); [ 'A', 'red' , 'boat'] [ 2 , 1, 3] 2**1**3**A**red**boat [ 'A', 'red' , 'boat'] [ 1 , 3, 7] 8**A**red**boat [ 'A', 'red' , 'boat'] [ 3 , 2, 1] A**red**boat [ 'A', 'red' ,...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) cout << (j + k) << endl; } d. while (n > 1) { k += n *3; n = n / 2; } e. int temp = n; for (int j...
Write the c++ code that will run with visual studio With the square function below as an example, write a max function that has two int parameters and will return back the larger of the two. Also write a main which can be used to test your function. ex ) int square(intnum); // funcprototype int main() { inta = 5, b; a = square(a); b = square(4);cout<< square( 6 ) << endl; .... // func...
There is a syntax error in the object below. Which of the following adjustments will make this code correct? var superman = { firstName: "Clark", lastName: "Kent", revealIdentity function() { return this.firstName + " " + this.lastName; } }; a. firstName: "Clark"; b. revealIdentity: function () { c. return firstName + " " + lastName; d. var superman {
The following code is given for the class Student: class Student{ var choice1, choice2, name; var numberOfChoices = 0; constructor(studentName){ this.choice1 = null; this.choice2 = null; this.choice3 = null; this.name = studentName; } getName = function(){ return this.name; }; setChoice = function(c){ if(numberOfChoices ==0){ this.choice1 = c; numberOfChoices++; } else{this.choice2 =c; }; getChoice1 = function(){ return this.choice1(); };} Write a section of code that creates a new StudentChoice object with name "Tom". Then set choice1 to "Algebra Review";
# 3. The following code draws a sample of size $n=30$ from a chi-square distribution with 15 degrees of freedom, and then puts $B=200$ bootstrap samples into a matrix M. After that, the 'apply' function is used to calculate the median of each bootstrap sample, giving a bootstrap sample of 200 medians. "{r} set.seed (117888) data=rchisq(30,15) M=matrix(rep(0,30*200), byrow=T, ncol=30) for (i in 1:200 M[i,]=sample(data, 30, replace=T) bootstrapmedians=apply(M,1,median) (3a) Use the 'var' command to calculate the variance of the bootstrapped medians....
Exercises • Determine running time for the following code fragments: (a) a = b + c; d = a + e; (b) sum = 0; for (i=0; i<3; i++) for (j=0; j<n; j++) sum++; (c) sum=0; for (i=0; i<n<n; i++) sum++; (d) for (i=0; i < n-1; i++) for (j=i+1; j <n; j++) { tmp = A[i][j]; A[i][j] = A[j] [i]; A[j][i] = tmp; (e) sum = 0; for (i=1; i<=n; i++) for (j=1; j<=n; j+=2) sum++;
Question 21 Implement the following code fragments in Hack Virtual Machine code, the variables a, b and c are in the local segment at offsets 4, 5 and 6 respectively. Jack Code a)-(alb) Virtual Machine Code [4 marks] b) (a(b+c) 5 marks] [5 marks] d) Recursive.factorial(6) 2 marks] e) a # c * b 4 marks] Total for Question 21: 20 marks] Question 21 Implement the following code fragments in Hack Virtual Machine code, the variables a, b and c...