Skip to content

Instantly share code, notes, and snippets.

@0xcrypto
Created January 26, 2017 15:56
Show Gist options
  • Save 0xcrypto/bf841848d523b9c70d896cb6e65abf2f to your computer and use it in GitHub Desktop.
Save 0xcrypto/bf841848d523b9c70d896cb6e65abf2f to your computer and use it in GitHub Desktop.
love-calc for techadvises.com
var app = angular.module('lCalc', []); // init angular app
app.controller('calcCtrl', [
// controller definition
'$scope',
function($scope) {
$scope.calculate = function(){
if($scope.first == "" || $scope.second == "") {
$scope.percentage = "Enter names first!";
}
else {
total = $scope.first.length + $scope.second.length;
countchars = countreps($scope.first+$scope.second);
sum = 0;
for(var i = 0; i < countchars.length; i++) {
sum += countchars[i];
}
percentage = (sum/total) * 100;
percentage+= 50;
if(percentage > 80) {
percentage -= 50;
}
$scope.percentage = percentage.toFixed(2) + "%";
}
};
}]);
countreps = function(str) {
// counts number of characters matched
str = str.split('');
charc = [];
strtmp = str.slice();
while(strtmp.length) {
char = strtmp.shift();
count = 0;
for(var i = 0; i < str.length; i++) {
if(char === str[i]) {
count++;
}
}
charc.push({char:char, count: count})
}
values = [];
for(var i = 0; i < charc.length; i++) {
values.push(charc[i].count);
}
var retcharc = [];
$.each(values, function(i, el){
if($.inArray(el, retcharc) === -1) retcharc.push(el);
});
return retcharc;
}
$(document).ready(function(){$('#calc-start').fadeIn(3000)})
.calc-cover {
position: absolute;
top:0;
margin-left:auto;
margin-right:auto;
left:0;
right:0;
background:white;
z-index: 1000;
font-family: 'Ubuntu Condensed';
color:red;
text-align: center;
width:70%;
height:500px;
}
.calc-cover h1{
margin-top:100px;
}
.calc-body {
display: none;
font-family: 'Ubuntu Condensed';
color:red;
text-align: center;
margin:auto;
width:70%;
height:500px;
}
.calc-fa-heart {
color:red;
font-weight: 900;
font-size:48px;
}
.calc-table {
margin:auto;
padding:10px;
}
.calc-input {
width:100%;
background:#ffdada;
color:red;
border:none;
padding:10px;
font-weight: bolder;
outline: none;
}
.calc-submit-button {
outline: none;
background:#ff8080;
color:white;
border:none;
box-shadow: 1px 1px 1px #333;
padding:10px;
transition: 0.5s background, linear 0.1s box-shadow;
cursor:pointer;
text-transform: uppercase;
font-family: 'Ubuntu Condensed';
font-size:24px;
}
.calc-submit-button:hover,
.calc-submit-button:focus{
background:#ff0000;
box-shadow: 3px 3px 3px #333;
}
.calc-result {
font-weight:bolder;
font-size:48px;
margin:20px;
}
.calc-credits a {
font-style: normal;
text-decoration:none;
color:red;
transition:1s color;
}
.calc-credits a:hover {
color:#ff8080;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment