AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



javascript-array: Write a function to calculate Max of Min of series given

Help to solve please really need!
A list of numbers A (2n) is given. Develop a program that calculates a value: Z = max (min (A (1) ... A (2n), min (A(2) ... A (2n-1)), ..., min (A (n) ... A (n+1)))

javascript x 33
array x 12
Posted On : 2018-03-06 11:50:36.0
profile Aryan Gupta - anyforum.in Aryan Gupta
1900
up-rate
4
down-rate

Answers


<html>
<title>Array Max Min- anyforum.in</title>
<script type="text/javascript">
Array.prototype.max = function() {
return Math.max.apply(null, this);
};

Array.prototype.min = function() {
return Math.min.apply(null, this);
};

function getMaxMin(array){
var n=array.length/2;
var newArray=[];
for(var i=1;i<=n;i++){
newArray[i-1]= array.slice(i-1, 2*n-1).min();
}
return newArray.max();
}
</script>
<body>
Array Max Min for [1, 10, 2, 4, 6, 7, 8, 9] is: <script type="text/javascript">document.write(getMaxMin([1, 10, 2, 4, 6, 7, 8, 9]))</script>
</body>
</html>

Posted On : 2018-03-11 14:47:59
Satisfied : 3 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222646
Reply This Thread
up-rate
1
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in