accessing Object()...

C

Cmac

Hello All,
I have created a custom object()
var o_table = new Object();

o_table['0'] = 240;
o_table['1'] = 241;
o_table['2'] = 242;
o_table['3'] = 243;
o_table['4'] = 244;
o_table['5'] = 245;
o_table['6'] = 246;
o_table['7'] = 247;
o_table['8'] = 248;
o_table['9'] = 249;
o_table['A'] = 193;
o_table['B'] = 194;
o_table['C'] = 195;
o_table['D'] = 196;
o_table['E'] = 197;
o_table['F'] = 198;
o_table['G'] = 199; // *
o_table['H'] = 200;
o_table['I'] = 201; // **
o_table['J'] = 209;
o_table['K'] = 210;
o_table['L'] = 211;
o_table['M'] = 212;
o_table['N'] = 213;
o_table['O'] = 214; // **
o_table['P'] = 215;
o_table['Q'] = 216; // **
o_table['R'] = 217;
o_table['S'] = 226; // *
o_table['T'] = 227;
o_table['U'] = 228;
o_table['V'] = 229;
o_table['W'] = 230;
o_table['X'] = 231;
o_table['Y'] = 232;
o_table['Z'] = 233; // **

I have a seven character string I get from an input in a form. I need
to take the characters from this string and I do this...

var splitupaa = doc.aainput.value.split("");//0 - 6

so now I have an 'array'.

QUESTION:
How can I take splitupaa[] and equate the value to the key in the
Object() ???

ex if input string is 1234567
in my object
1 = 240
2 = 241
etc.

I need to compute an algorithm with the values from the object relative
to the array values.

Thanks in advance!
( I am starting to like JS now ;) )
Cmac
 
R

RobG

Cmac said:
Hello All,
I have created a custom object()
var o_table = new Object();

o_table['0'] = 240;
o_table['1'] = 241; [...]
o_table['Y'] = 232;
o_table['Z'] = 233; // **

Consider initialising that with:

var o_table = {
'0' : 240,
'1' : 241,
[...]
'Y' : 232,
'Z' : 233
}


Are the values ever used as numbers? If not, why not make them strings?

var o_table = {
'0' : '240',
'1' : '241',
[...]
'Y' : '232',
'Z' : '233'
}


I have a seven character string I get from an input in a form. I need
to take the characters from this string and I do this...

var splitupaa = doc.aainput.value.split("");//0 - 6

so now I have an 'array'.

QUESTION:
How can I take splitupaa[] and equate the value to the key in the
Object() ???

ex if input string is 1234567
in my object
1 = 240
2 = 241
etc.

I need to compute an algorithm with the values from the object relative
to the array values.

function encodeStr(s)
{
s = String(s).split('');
var s2 = '';
for (var i=0, len=s.length; i<len; ++i){
s2 += o_table[s];
}
return s2;
}


Or:

function encodeStr(s)
{
s = String(s).split('');
var s2 = [];
for (var i=0, len=s.length; i<len; ++i){
s2.push(o_table[s]);
}
return s2.join('');
}
 
C

Cmac

var ibmalgo = new Object();

ibmalgo['0'] = 240;
ibmalgo['1'] = 241;
ibmalgo['2'] = 242;
ibmalgo['3'] = 243;
ibmalgo['4'] = 244;
ibmalgo['5'] = 245;
ibmalgo['6'] = 246;
ibmalgo['7'] = 247;
ibmalgo['8'] = 248;
ibmalgo['9'] = 249;
ibmalgo['A'] = 193;
ibmalgo['B'] = 194;
ibmalgo['C'] = 195;
ibmalgo['D'] = 196;
ibmalgo['E'] = 197;
ibmalgo['F'] = 198;
ibmalgo['G'] = 199;
ibmalgo['H'] = 200;
ibmalgo['I'] = 201;
ibmalgo['J'] = 209;
ibmalgo['K'] = 210;
ibmalgo['L'] = 211;
ibmalgo['M'] = 212;
ibmalgo['N'] = 213;
ibmalgo['O'] = 214;
ibmalgo['P'] = 215;
ibmalgo['Q'] = 216;
ibmalgo['R'] = 217;
ibmalgo['S'] = 226;
ibmalgo['T'] = 227;
ibmalgo['U'] = 228;
ibmalgo['V'] = 229;
ibmalgo['W'] = 230;
ibmalgo['X'] = 231;
ibmalgo['Y'] = 232;
ibmalgo['Z'] = 233;



var splitupaa = doc.aainput.value.split("");//0 - 6


//A1 + A3 + A3 + A5 + A4 + A6 / 5
var calculation = (ibmalgo[splitupaa[0]] + ibmalgo[splitupaa[2]] +
ibmalgo[splitupaa[2]] + ibmalgo[splitupaa[4]] + ibmalgo[splitupaa[3]] +
ibmalgo[splitupaa[5]]) / 5;
document.write(calculation);


This does not do what I want it to, but maybe you will see what I am
trying to do???
 
U

UnaCoder

you are skipping charecter at index 1, and adding the charecter at
index 2 twice, i'm assuming this is what you want to do... also if
you're looking for the average, there are 6 charecters at indexes 0 to
5... I'm guessing you knew all this already but i thought i'd point it
out anyways
 
C

Cmac

Thanks, this is how I fixed the issue:

var ibmalgo = new Object();

ibmalgo['0'] = 240;
ibmalgo['1'] = 241;
ibmalgo['2'] = 242;
ibmalgo['3'] = 243;
ibmalgo['4'] = 244;
ibmalgo['5'] = 245;
ibmalgo['6'] = 246;
ibmalgo['7'] = 247;
ibmalgo['8'] = 248;
ibmalgo['9'] = 249;
ibmalgo['A'] = 193;
ibmalgo['B'] = 194;
ibmalgo['C'] = 195;
ibmalgo['D'] = 196;
ibmalgo['E'] = 197;
ibmalgo['F'] = 198;
ibmalgo['G'] = 199;
ibmalgo['H'] = 200;
ibmalgo['I'] = 201;
ibmalgo['J'] = 209;
ibmalgo['K'] = 210;
ibmalgo['L'] = 211;
ibmalgo['M'] = 212;
ibmalgo['N'] = 213;
ibmalgo['O'] = 214;
ibmalgo['P'] = 215;
ibmalgo['Q'] = 216;
ibmalgo['R'] = 217;
ibmalgo['S'] = 226;
ibmalgo['T'] = 227;
ibmalgo['U'] = 228;
ibmalgo['V'] = 229;
ibmalgo['W'] = 230;
ibmalgo['X'] = 231;
ibmalgo['Y'] = 232;
ibmalgo['Z'] = 233;



var splitupaa = doc.aainput.value.split("");//0 - 6
var A1 = splitupaa[0].toUpperCase();
var A2 = splitupaa[1].toUpperCase();
var A3 = splitupaa[2].toUpperCase();
var A4 = splitupaa[3].toUpperCase();
var A5 = splitupaa[4].toUpperCase();
var A6 = splitupaa[5].toUpperCase();
var A7 = splitupaa[6].toUpperCase();

//A1 + A3 + A3 + A5 + A4 + A6 / 5
var calculation = (ibmalgo[A1] + ibmalgo[A3] + ibmalgo[A3] +
ibmalgo[A5] + ibmalgo[A4] + ibmalgo[A6]) / 5;

I really appreciate all your help out there in interweb land ;-)
Cmac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top