...

View Full Version : 2 Developers. 2 Methods. Who is right?



salesforce123
06-12-2010, 02:43 AM
My question is about the following javascript function that converts 15 digit salesforce IDs to 18 digit salesforce IDs. The function was originally posted here (http://community.salesforce.com/t5/General-Development/GetUserInfoResult-getOrganizationId-does-not-equal-OrgID/m-p/152788/highlight/false).

Developer 1 wrote the function:

function convertToCaseInsensitiveId(id) {
var hash = '';
for (var c = 0; c < 3; c++) {
var h = 0;
for (var i = 0; i < 5; i++) {
var ch = id.charCodeAt(i + c * 5);
if (ch >= 65 && ch <= 91) h += Math.pow(2, i);
}
hash += String.fromCharCode(h > 26 ? h + 48 - 26 : h + 65);
}
return id + hash;
}

Developer 2 said:

Since the checksum numbers are mapped to AB..YZ012345, 25 gives Z. The following line

> hash += String.fromCharCode(h > 26 ? h + 48 - 26 : h + 65);
should be
> hash += String.fromCharCode(h > 25 ? h + 48 - 26 : h + 65);
otherwise 26 would be mapped to opening bracket (ASCII # 91).


Which developer's solution is correct?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum