Advanced Constructs Advanced Function Concepts
Advanced Constructs Advanced Function Concepts
Function Concepts
Assignment Questions
Assignment Questions
Assignment Questions
Problem 1:
A subarray of an array is defined as the contiguous cross section of the array. Example: [1,2,3] has the
following subarrays: [1],[2],[3],[1,2],[2,3].[1,2,3] Given an array print all the subarrays of the given array
Example-1
Input: [1,2,3]
Output: [1],[2],[3],[1,2],[2,3].[1,2,3]
Problem 2:
You have an array of n elements. Your job is to find the element that is in majority.
Any element whose count is greater than n/2 will be considered as a majority element.
Example-1:
Input: [3,1,3,3,2]
Output: 3
MCQ (Day 6)
function makeAdder(x) {
return x + y;
};
console.log(addFive(3));
A. overloading
B. closure
C. currying
D. overriding
Assignment Questions
D. None of these
var x = 1
var x1 = function () {
console.log(x);
};
var y2 = function () {
var x = 2;
x1();
};
y2();
A. 1
B. 2
C. error
D. undefined
var x = [ 1, 2, 3, 4, 5, 6, 7 ]
};
console.log(f(x));
A. [4,5,6,7,8,9,10]
B. [4,5,6,7]
C. [1,2,3,4,5,6]
D. [4,5,6]
Function Concepts
Assignment Solutions
Assignment Solutions
Assignment Solutions
Solution 1:
function subArray(n) {
document.write("</br>");
subArray(arr.length);
Solution 2:
function findMajority(arr, n)
let maxCount = 0;
let count = 0;
if (arr[i] == arr[j])
count++;
maxCount = count;
index = i;
if (maxCount > n / 2)
document.write(arr[index]);
else
let n = arr.length;
findMajority(arr, n);
Assignment Solutions
MCQ Answers