This takes any string of characters and totals up how much it would be worth in Scrabble. It ignores any spaces or other non alphabet characters. It doesn't factor in any premium letter or word squares, and it doesn't care if you provide more letters than could possibly fit on a real Scrabble board.
function scrabbleScore(word) {
var scores = [1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10];
var score = 0;
word = word.toUpperCase();
for (var i=0; i<word.length; i++) {
var n = word.charCodeAt(i) - 65;
if (n<0 || n>25) continue;
score += scores[n];
}
return score;
}
Subscribe to:
Post Comments (Atom)
Blog Archive
- May 2019 (3)
- November 2015 (1)
- September 2015 (1)
- May 2014 (1)
- March 2014 (1)
- February 2014 (2)
- January 2014 (1)
- September 2013 (2)
- August 2013 (1)
- April 2013 (3)
- March 2013 (2)
- February 2013 (1)
- January 2013 (1)
- December 2011 (1)
- October 2011 (1)
- September 2011 (12)
- July 2011 (2)
- March 2011 (1)
- January 2010 (2)
- December 2009 (2)
- December 2008 (4)
- November 2008 (4)
- October 2006 (1)
- September 2006 (1)
- August 2006 (1)
- February 2006 (1)
- January 2006 (3)
No comments:
Post a Comment