แก้ coding style ภาค 10

This commit is contained in:
Pitchaya Boonsarngsuk
2018-03-22 16:40:27 +00:00
parent 400eab7e80
commit cd0f3687cb
14 changed files with 104 additions and 109 deletions

View File

@@ -6,33 +6,33 @@
* @param {node} target
* @return {number} the distance between source and target nodes.
*/
function calculateDistancePoker(source, target) {
function calculateDistancePoker (source, target) {
var sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 1.5,
cards = ["C1", "C2", "C3", "C4", "C5"],
cols = 0;
ordDiff = 1.0,
ORD_FACTOR = 1.5,
cards = ['C1', 'C2', 'C3', 'C4', 'C5'],
cols = 0;
// Iterate through cards
for (var i = 0; i < cards.length; i++) {
card = cards[i];
if (source.hasOwnProperty(card) && target.hasOwnProperty(card)) {
var s = parseInt(source[card]),
t = parseInt(target[card]);
t = parseInt(target[card]);
// Calculate the squared difference.
sumDiff += (s-t) * (s-t);
sumDiff += (s - t) * (s - t);
}
}
// Class of poker hands describes the similarities the best
// so give it more priority than checking the differences between cards.
if (source.hasOwnProperty("CLASS") && target.hasOwnProperty("CLASS")) {
var s = parseInt(source["CLASS"]),
t = parseInt(target["CLASS"]);
if (source.hasOwnProperty('CLASS') && target.hasOwnProperty('CLASS')) {
var s = parseInt(source['CLASS']),
t = parseInt(target['CLASS']);
// If classes differ, then scale them by a factor.
if (s !== t) {
ordDiff *= (ORD_FACTOR * (Math.abs(s-t)))
ordDiff *= (ORD_FACTOR * (Math.abs(s - t)));
}
}
@@ -40,4 +40,4 @@ function calculateDistancePoker(source, target) {
sumDiff *= ordDiff;
return sumDiff;
}
}