473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to find maximum value among X number of points?

5 New Member
This is all i have right now and i cant figure out how to go further..

Expand|Select|Wrap|Line Numbers
  1.      var numEntries;
  2.                     var max;
  3.                     var pt;                                       
  4.  
  5.                     numEntries = Number(prompt("Number of entries to process?"));
  6.  
  7.                     do {                
  8.                         pt = Number(prompt("Enter data point");
  9.                         numEntries = numEntries - 1
  10.  
  11.                     while ((numEntries - 1) !== 0);
  12.                     }
Jan 12 '10 #1
2 2462
gits
5,390 Recognized Expert Moderator Expert
you might split that into 2 steps ... let me give you an idea for that:
Expand|Select|Wrap|Line Numbers
  1. var numEntries;
  2. var max;
  3. var pt = [];                                       
  4.  
  5. numEntries = parseInt(
  6.     prompt("Number of entries to process?"), 10
  7. );
  8.  
  9. for (var i = 0; i < numEntries; ++i) { 
  10.     pt[i] = parseFloat(prompt("Enter data point"));
  11. }
  12.  
  13. alert(pt.toString());
  14.  
  15. // so now process the max finding here for the array pt
  16.  
kind regards

PS: you could even use one step of course ... just remember the bigger values through the inputs in a variable like this:
Expand|Select|Wrap|Line Numbers
  1. if (typeof max == 'undefined' || pt[i] > max) {
  2.     max = pt[i];
  3. }
Jan 12 '10 #2
xNephilimx
213 Recognized Expert New Member
You can use Math.max() to find the max number like:

Expand|Select|Wrap|Line Numbers
  1. max = eval("Math.max("+pt.join(',')+")");
  2.  
Jan 12 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Till Crueger | last post by:
Hi, I have to implement some simple sorting algorithm. I am NOT asking for you to do my homework, but my question is rather on how to store the integers. I recall reading once in here that there...
19
by: Jerry | last post by:
I am wondering what is the maximum size of memory that malloc() could handle. Is there any limitation on that? Where am I supposed to get this kind of information? Thank you everybody.
50
by: sabarish | last post by:
Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
21
by: Imran | last post by:
I have a vector of integers, such as and I want to find out the number which occurs most frequently.what is the quick method. My array size is huge. what I am doing is 1. find out the...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
6
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value =...
5
by: JD | last post by:
Hi, There are about 10+ 3-D points on the same line. I want to find the two end points from these points. The efficiency is not an issue because there are only 10 points or so. I just need a...
2
choke
by: choke | last post by:
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find...
4
by: lightaiyee | last post by:
Dear Gurus, I would like to implement a function that computes the number of times a certain condition is met in a global array. For example, I have an global array of size 500. float array;...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.