I have a sheet that shows Items Cost. What I want to do instead of showing numbers i want to use the following BLACKHORSE were B = 1, L = 2, A = 3,C=4,K=5,H=6,7=O,8=R,9=S and E=0. How do i put this in a script in Google Sheets to where say cell h9 the sum of the total cost of the items it puts the letters instead of numbers
Asked
Active
Viewed 120 times
-1
-
So, if the total cost were 30, what are you expecting? – AAA Jul 22 '19 at 23:20
-
FWIW-an [isogram](https://en.wikipedia.org/wiki/Isogram) is a word with no repeating letter. Ten letter isograms enable representations of the numbers 1-10. Wikipedia says Ten-letter isograms like PATHFINDER, DUMBWAITER, and BLACKHORSE are commonly used by salespeople of products where the retail price is typically negotiated, such as used cars, jewelry, or antiques. In the PATHFINDER cipher, P=1, A=2, etc. So if an item selling for $1200 bears the cryptic letters FRR, a salesman will know that the original cost of the item was $500 and be better able to negotiate. – Tedinoz Jul 23 '19 at 12:08
-
@AAA If the cost of an item was $30, then the "BLACKHORSE" value would be AE. – Tedinoz Jul 23 '19 at 12:26
1 Answers
1
There may be many ways to calculate the values that you want. Consider this as one approach.
function so5715442701() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetname = "57154427";
var sheet = ss.getSheetByName(sheetname);
// code to find the key for a given value in a javascript key:value array
Object.prototype.getKey = function(value){
for(var key in this){
if(this[key] == value){
return key;
}
}
return null;
};
// a key:value array for BLACKHORSE
var blackhorse = {
B : 1,
L : 2,
A : 3,
C : 4,
K : 5,
H : 6,
O : 7,
R : 8,
S : 9,
E : 0
};
// get the cost value from a cell
var costprice = sheet.getRange("C15").getValue();
// convert the number to a string
var cost = costprice.toString(); // convert to string
//Logger.log("DEBUG: cost = "+cost+", length = "+cost.length);
// set a variable to accumulate the results
var costtotal="";
// loop through the characters in the cost value
for (var i = 0; i < cost.length; i++) {
var letter = cost.charAt(i);
var costkey = blackhorse.getKey(letter);
var costtotal = costtotal+costkey
}
//Logger.log("DEBUG: cost = "+cost+", Blackhourse cost = "+costtotal);
sheet.getRange("D15").setValue(costtotal);
}
CREDIT
- How can I process each letter of text using Javascript?
- How to get a key in a JavaScript object by its value?

Tedinoz
- 5,911
- 3
- 25
- 35