Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="cardRates">
<h3>PAYOUT</h3>
</div>
</body>
</html>
var payout = [{'K': [1.04, null]},
{'Q': [1.13, 12.48]},
{'J': [1.25, 6.24]},
{'T': [1.39, 4.16]},
{'9': [1.56, 3.12]},
{'8': [1.78, 2.50]},
{'7': [2.08, 2.08]},
{'6': [2.50, 1.78]},
{'5': [3.12, 1.56]},
{'4': [4.16, 1.39]},
{'3': [6.24, 1.25]},
{'2': [12.48, 1.13]},
{'A': [null, 1.04]},
{'0': [null, null]}
];
var toObject = function(array){
var newObj = {};
for(var i = 0; i<array.length; i++){
newObj[i] = {};
for(var k in array[i]){
if(array[i].hasOwnProperty(k)){
newObj[i][k] = array[i][k];
}
}
}
return newObj;
};
var createPayoutTable = function(){
var table = $('<table/>');
var row, cell;
table.className = 'payoutTable';
_.each(payout, function(e){
_.each(e, function(v, k){
if (k !== '0'){
row = $('<tr/>');
var head = $('<td/>');
head.append(k);
row.append(head);
_.each(v, function(i) {
cell = $('<td/>');
cell.append(i || '-');
row.append(cell);
});
table.append(row);
}
});
});
$('.cardRates').append(table);
};
var someThing = [
{'name': 'John', 'surname': 'Doe', 'age': 12},
{'name': 'Jane', 'surname': 'Doe', 'age': 47},
{'name': 'Ali', 'suranme': 'Yildiz', 'age': 25},
{'name': 'Hello', 'surname': 'World', 'age': 33}
];
createPayoutTable();
console.log(toObject(someThing));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment