public
Last active

js :: lucky number for your name

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
(function (name) {
var alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
chars = name.toLowerCase().split(' ').join('').split(''),
valueOf = function (c) {
var i = 0, n = alpha.length;
for (; i < n; i += 1) {
if (alpha[i] == c) {
return i + 1;
}
}
return 0;
},
sum = 0;
for (i in chars) {
sum += valueOf(chars[i]);
}
console.log(sum);
})('chandu');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.