473,432 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

sort out duplicated fax numbers

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
May 10 '06 #1
4 2706
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/>
May 10 '06 #2
ASM
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
May 10 '06 #3
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/>

May 11 '06 #4
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.
May 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
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...
1
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() {
7
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
11
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...
21
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...
0
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...
7
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...
75
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...
9
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>...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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?

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.