sum of "attitude" alphabet to number are equals 100? just for fun..
Created
May 9, 2015 13:06
-
-
Save aifarfa/bd81e6ea525f7744c97a to your computer and use it in GitHub Desktop.
alphabet to number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div role="dialog" ng-app="Attitude"> | |
<h2>attitude 100%</h2> | |
<div ng-controller="TestCtrl"> | |
{{itWork}} | |
<div> | |
<input type="text" ng-model="word" ng-change="doIt()" /> | |
value: {{wordValue}} | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('Attitude', []). | |
controller('TestCtrl', ['$scope', function($scope) { | |
$scope.itWork = 'Try another word'; | |
$scope.alphabets = getAlphabet(); | |
$scope.word = 'Attitude'; | |
$scope.doIt = function() { | |
//if(!$scope.word.length) return; | |
var word = $scope.word.toLowerCase(); | |
$scope.wordValue = sumOfWordValue(word); | |
}; | |
$scope.doIt(); | |
function sumOfWordValue(word) { | |
var result = 0; | |
for (var i = 0; i < word.length; i++) { | |
result += alphabetToNumber(word[i]); | |
} | |
return result; | |
} | |
function alphabetToNumber(char) { | |
return $scope.alphabets.indexOf(char) + 1; | |
} | |
function getAlphabet() { | |
var result = []; | |
for (var i = 97; i < 123; i++) { | |
var char = String.fromCharCode(i) | |
result.push(char) | |
} | |
return result; | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment