i have a number of forms with fax numbers to come up into arrays and then
combine to string.
after that i design the flow
1. break the string to array
now the string looks like this 12345678,23456789,34567890...
2. check record-2 again record-1,
check record-3 again record-2 & record-1
check record-4 again record-3 & record-2 & record-1
and so on... (if duplicated, drop it)
problem - step 1 break the string to array
var CDEF = new Array(faxnumbers);
alert(CDEF[0],
it returns all the numbers (12345678,23456789,34567890...
i just wish to have 12345678
anything wrong with my script?
Grateful if you could kindly advise whether step 2 is the best way to sort
out duplicated numbers?
Thanks a lot
tony 4 2698
Tony WONG wrote: i have a number of forms with fax numbers to come up into arrays and then combine to string.
after that i design the flow 1. break the string to array now the string looks like this 12345678,23456789,34567890... 2. check record-2 again record-1, check record-3 again record-2 & record-1 check record-4 again record-3 & record-2 & record-1 and so on... (if duplicated, drop it)
problem - step 1 break the string to array var CDEF = new Array(faxnumbers); alert(CDEF[0],
it returns all the numbers (12345678,23456789,34567890...
i just wish to have 12345678
anything wrong with my script?
Yes, it's very inefficient. If you start with a comma-delimited set of
numbers, you can split it into an array using split:
var faxNumbers = '1234,2345,3456,45646,...';
var faxNumArray = faxNumbers.split(',');
Now to get unique numbers, sort the array and load only new ones into a
new array (the numbers are sorted alphabetically, but since they are all
numbers that shouldn't matter here):
faxNumArray.sort();
var faxNumUnique = [faxNumArray[0]];
for (var i=1, j=0, len=faxNumArray.length; i<len; ++i){
if (faxNumArray[i] != faxNumUnique[j]){
faxNumUnique[++j] = faxNumArray[i];
}
}
// faxNumUnique now contains a sorted, unique list of fax numbers
Grateful if you could kindly advise whether step 2 is the best way to sort out duplicated numbers?
No, it's not. The best way would be to use a UNIX sort unique, but
since this is JavaScript ... see above.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
Tony WONG a écrit : i have a number of forms with fax numbers to come up into arrays and then combine to string.
after that i design the flow 1. break the string to array now the string looks like this 12345678,23456789,34567890... 2. check record-2 again record-1, check record-3 again record-2 & record-1 check record-4 again record-3 & record-2 & record-1 and so on... (if duplicated, drop it)
problem - step 1 break the string to array var CDEF = new Array(faxnumbers);
CDEF = faxnumbers.split(',');
alert(CDEF[0],
would be 12345678
--
Stephane Moriaux et son [moins] vieux Mac
Thanks a lot.
"RobG" <rg***@iinet.net.au>
???????:YH*******************@news.optus.net.au... Tony WONG wrote: i have a number of forms with fax numbers to come up into arrays and then combine to string.
after that i design the flow 1. break the string to array now the string looks like this 12345678,23456789,34567890... 2. check record-2 again record-1, check record-3 again record-2 & record-1 check record-4 again record-3 & record-2 & record-1 and so on... (if duplicated, drop it)
problem - step 1 break the string to array var CDEF = new Array(faxnumbers); alert(CDEF[0],
it returns all the numbers (12345678,23456789,34567890...
i just wish to have 12345678
anything wrong with my script?
Yes, it's very inefficient. If you start with a comma-delimited set of numbers, you can split it into an array using split:
var faxNumbers = '1234,2345,3456,45646,...'; var faxNumArray = faxNumbers.split(',');
Now to get unique numbers, sort the array and load only new ones into a new array (the numbers are sorted alphabetically, but since they are all numbers that shouldn't matter here):
faxNumArray.sort(); var faxNumUnique = [faxNumArray[0]]; for (var i=1, j=0, len=faxNumArray.length; i<len; ++i){ if (faxNumArray[i] != faxNumUnique[j]){ faxNumUnique[++j] = faxNumArray[i]; } } // faxNumUnique now contains a sorted, unique list of fax numbers
Grateful if you could kindly advise whether step 2 is the best way to sort out duplicated numbers?
No, it's not. The best way would be to use a UNIX sort unique, but since this is JavaScript ... see above.
-- Rob Group FAQ: <URL:http://www.jibbering.com/faq/>
JRS: In article <YH*******************@news.optus.net.au>, dated Wed,
10 May 2006 07:34:16 remote, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.au> posted : Yes, it's very inefficient. If you start with a comma-delimited set of numbers, you can split it into an array using split:
var faxNumbers = '1234,2345,3456,45646,...'; var faxNumArray = faxNumbers.split(',');
Now to get unique numbers, sort the array and load only new ones into a new array (the numbers are sorted alphabetically, but since they are all numbers that shouldn't matter here):
In sorting to determine duplicates, the sort order does not matter, and
hence there is no relevance in their being numbers. The only need is
that identical values sort to adjacent and that comparison of a given
pair is consistent.
The obvious javascript way is to do the built-in sort, then to make a
single pass removing repeats or copying non-repeats.
If the number of duplicates is large, however, it may be better to code
the sort explicitly using a reasonably efficient algorithm, but to then
modify it so that when two items are found to be equal one of them is
dropped.
OTOH, perhaps the most efficient sorts are non-stable (i.e. items
testing as identical do not have their order preserved) and do not use
comparison-for-equality.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David |
last post by:
sorry for the last post, itchy fingers.
I'm having a bit of difficulty sorting images named in sequential numerical
order. Here are the image names and how I need them sorted.
image1.jpg...
|
by: strotee |
last post by:
#include <iostream>
#include <ctime>
using namespace std;
// function declarations
void swap(int *a, int *b);
void sort(int arr, int beg, int end);
int main()
{
|
by: Amy |
last post by:
I'm trying to add an autoincrementing id to a table based on an
existing field Name, but Name has duplicated records. How can I do
that in ACCESS?
Thanks.
Amy
|
by: Leon |
last post by:
I have six textbox controls on my webform that allows the user to enter any
numbers from 1 to 25 in any order. However, I would like to sort those
numbers from least to greatest before sending them...
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: Slowjam |
last post by:
How do I correct the program below to search all the anagrams in a given file.
First, for each word, build another word (its key) with all its letters sorted. For instance, build "dorw" for...
|
by: ^cypis^ vel. SQ9JTI |
last post by:
Hi,
i need your help.
I have to prepare a homework, easy program, which will be sorting the
values from txt file and writing the solution to another txt file.
It has to be a bucket sort. Have...
|
by: At_sea_with_C |
last post by:
Hello all,
I have written an ascending sort routine for floats. This seems to do
the job, but for elements over 10,000, it gets awfully slow. A lot of
useless comparisions with previously sorted...
|
by: mosullivan |
last post by:
I can't figure out how to print after every pass through the bubble sort. I'm supposed to display the sort after every pass through the loop. Below is what I have so far.
#include <stdio.h>...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |