473,796 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compare string in array

Hi all,

I need some advice regarding wrote a javascript function.
The function purpose is to check the variable "selectedSe at",

for e.g if the selectedSeat value is

var selectedSeat = "A:01|A:03|A:05 |B:01|B:02|B:03 ";
var selectedArray = selectedSeat.sp lit("|");

because row A is not in sequence , i will display alert box to
user,
but row B is in sequence is ok.

Main purpose of function is check if the row is in the sequence.
I have been cracking my head about this , anyone have suggestion is
much appreciated.

The project is in voyager browser which are the clone of netscape
4.0, so some newer javascript code will not work.

Thanks

Wee Tat

Jun 12 '07 #1
3 2006
Lee
weetat said:
>
Hi all,

I need some advice regarding wrote a javascript function.
The function purpose is to check the variable "selectedSe at",

for e.g if the selectedSeat value is

var selectedSeat = "A:01|A:03|A:05 |B:01|B:02|B:03 ";
var selectedArray = selectedSeat.sp lit("|");

because row A is not in sequence , i will display alert box to
user,
but row B is in sequence is ok.

Main purpose of function is check if the row is in the sequence.
I have been cracking my head about this , anyone have suggestion is
much appreciated.

The project is in voyager browser which are the clone of netscape
4.0, so some newer javascript code will not work.
This doesn't require any special features (or even knowledge)
of Javascript. It's simply a matter of devising an algorithm.

Sort the array (if you don't know that it's already sorted)
and then step through the elements beginning with the second
one, ensuring that, if the alphabetic part is the same as
the previous element, that the numeric part is 1+ the numeric
part of that previous element.
--

Jun 12 '07 #2
weetat wrote:
The function purpose is to check the variable "selectedSe at",
for e.g if the selectedSeat value is

var selectedSeat = "A:01|A:03|A:05 |B:01|B:02|B:03 ";
var selectedArray = selectedSeat.sp lit("|");

because row A is not in sequence , i will display alert box
to user, but row B is in sequence is ok.

Main purpose of function is check if the row is in the
sequence.
var selectedSeat = 'A:01|A:03|A:05 |B:01|B:02|B:03 |C:02|D:1455'
selectedSeat += '|D:1456|ES:39| ES:38'
var selectedArray = selectedSeat.sp lit('|')
var obj = new Object()
var chars = new Array()
var okay = new Array()

for (var i=0; i < selectedArray.l ength; i++) {
var seat = selectedArray[i].split(':')
if (chars[chars.length-1] != seat[0]) chars.push(seat[0])
if (obj[seat[0]]) {
if (!obj[seat[0]][parseFloat(seat[1]-1)]) okay.push(seat[0])
}
else {
obj[seat[0]] = new Array()
}
obj[seat[0]][parseFloat(seat[1])] = 1
}

for (var j=0; j<chars.length ; j++) {
document.write( chars[j]+': ')
var neg = ''
for (var k = 0; k < okay.length; k++)
if (chars[j] == okay[k]) neg = 'no '
document.write( neg+'sequence <br>')
}

/* Notes:
1. Sequences must not start from 1 to be valid sequence
(eg. D:1455|D:1456 is okay)
2. selectedSeat must not be alphabetical, but the numbers
must be ordered per letter (eg. B:01|B:02|B:03 is okay,
B:01|B:03|B:02 is not okay)
3. Items consisting of only 1 letter (eg. C:02) are okay
*/

Hope this helps,

--
Bart

Jun 12 '07 #3

weetat wrote:
Hi all,

I need some advice regarding wrote a javascript function.
The function purpose is to check the variable "selectedSe at",

for e.g if the selectedSeat value is

var selectedSeat = "A:01|A:03|A:05 |B:01|B:02|B:03 ";
var selectedArray = selectedSeat.sp lit("|");

because row A is not in sequence , i will display alert box to
user,
but row B is in sequence is ok.

try:

s= "A:01|A:04|A:03 |B:01|B:02|B:03 ";
test(s)

function test(s){
var x={},ret='';
s=s.replace(/(\w):(\d+)(?=|)/g,function(a,b, c){x[b]=(x[b]||
[]).concat(c)});
for(var i in x)
for(var ii=1;ii<x[i].length;ii++)
if(x[i][ii]-1!= x[i][ii-1]){ret+=i+' - failed !!!'+"\n";break }
}

Jun 14 '07 #4

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

Similar topics

0
2714
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key' $formField2CompareWith: String to use as my comparison basis for second array. Same default as...
12
29474
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
3
10559
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the format was different. Basically you can sort a class having members LastName (string), FirstName (string) and Age (int) according to whether you want to sort by Last Name, First Name or Age, using the .Sort function
4
4245
by: toadstool | last post by:
I have an array containing the various products $inventory = array(); $inventory = "whatever1"; etc I have an array containing various values $quantity = array(100,200,300); I call in a value from a form $_POST; say I assign a variable
17
1892
by: toadstool | last post by:
I have an array containing the various products $inventory = array(); $inventory = "whatever1"; etc I have an array containing various values $quantity = array(100,200,300); I call in a value from a form $_POST; say I assign a variable $var1="$_POST";
0
9530
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10236
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.