แก้ 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,23 +6,23 @@
* @param {object} normArgs - the normalization arguments.
* @return {number} the distance between source and target nodes.
*/
function calculateDistance(source, target, properties, normArgs) {
function calculateDistance (source, target, properties, normArgs) {
var val1 = 0.0, val2 = 0.0,
sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 0.75,
cols = 0,
average = normArgs.avg,
sigma = normArgs.sig,
st_dev = normArgs.st_d;
sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 0.75,
cols = 0,
average = normArgs.avg,
sigma = normArgs.sig,
st_dev = normArgs.st_d;
// Iterate through every column of data
for (var i = 0; i < properties.length; i++) {
property = properties[i];
if (source.hasOwnProperty(property) && target.hasOwnProperty(property)
&& property.toLowerCase() !== "index" && property.toLowerCase() !== "type") {
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
property.toLowerCase() !== 'index' && property.toLowerCase() !== 'type') {
var s = source[property],
t = target[property];
t = target[property];
// Comparing Floats and Integers
if ((isNumeric(s) && isNumeric(t))) {
@@ -32,7 +32,7 @@ function calculateDistance(source, target, properties, normArgs) {
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
}
sumDiff += (val1-val2) * (val1-val2);
sumDiff += (val1 - val2) * (val1 - val2);
cols++;
// Comparing strings
} else if (/[a-zA-Z]/.test(s) && /[a-zA-Z]/.test(t) && s === t) {
@@ -42,9 +42,8 @@ function calculateDistance(source, target, properties, normArgs) {
// Comparing Dates
var parsedDateS = Date.parse(s);
var parsedDateT = Date.parse(t);
if (isNaN(s) && !isNaN(parsedDateS)
&& isNaN(t) && !isNaN(parsedDateT)) {
if (isNaN(s) && !isNaN(parsedDateS) &&
isNaN(t) && !isNaN(parsedDateT)) {
val1 = parsedDateS.valueOf(),
val2 = parsedDateT.valueOf();
@@ -52,7 +51,7 @@ function calculateDistance(source, target, properties, normArgs) {
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
}
sumDiff += (val1-val2) * (val1-val2);
sumDiff += (val1 - val2) * (val1 - val2);
cols++;
}
}
@@ -62,9 +61,9 @@ function calculateDistance(source, target, properties, normArgs) {
sumDiff *= ordDiff;
if (cols > 0) {
sumDiff *= properties.length/cols;
sumDiff *= properties.length / cols;
}
//console.log(sumDiff);
// console.log(sumDiff);
return sumDiff;
}