Last active
February 15, 2018 13:03
-
-
Save wing-puah/7e70abb1edce6b615827158d0f3fbf94 to your computer and use it in GitHub Desktop.
Define condition of person finding Match and define match
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
| function greaterThan( value, other ){ | |
| if( value > other ){ | |
| return 1; | |
| } else { | |
| return 0; | |
| } | |
| } | |
| function matchTheMatch(el) { | |
| if(el > 50 ){ | |
| console.log('This might be a good match'); | |
| } else { | |
| console.log('This does not seem like a good match'); | |
| } | |
| } |
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
| function calculateScore(Person, Match){ | |
| let that = Person, | |
| match = Match, | |
| condition = [], | |
| matchCondition = [], | |
| conditionScore = [], | |
| scoreMultiplication = [], | |
| finalScore = []; | |
| condition = condition.concat(that.height, that.weight, that.hobby); | |
| conditionScore = conditionScore.concat(that.hW, that.wW, that.hoW); | |
| conditionsOfMatch = matchCondition.concat(match.height, match.weight, match.hobby); | |
| function hobbyMatch(){ | |
| if (conditionsOfMatch[2] === condition[2]) { | |
| return 1; | |
| } else { | |
| return 0; | |
| } | |
| } | |
| for (var i = 0; i < condition.length - 1 ; i++){ | |
| scoreMultiplication[i] = greaterThan(conditionsOfMatch[i], condition[i]); | |
| scoreMultiplication.concat(scoreMultiplication[i]); | |
| } | |
| scoreMultiplication.push(hobbyMatch()); | |
| let conditionCalc = []; | |
| for (var i = 0; i < conditionScore.length - 1 ; i++){ | |
| conditionCalc.push(scoreMultiplication[i]*conditionScore[i]); | |
| } | |
| conditionScore = conditionScore.reduce( (a,b) => a + b ); | |
| finalScore = (conditionCalc.reduce( (a,b) => a + b ) / conditionScore * 100).toFixed(2); | |
| matchTheMatch(finalScore); | |
| } |
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
| function hobbyMatch(){ | |
| if (conditionsOfMatch[2] === condition[2]) { | |
| return 1; | |
| } else { | |
| return 0; | |
| } | |
| } |
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
| function ConditionsToLookFor( height, hW, weight, wW, hobby, hoW ) { | |
| this.height = height || 15; | |
| this.hW = hW; | |
| this.weight = weight; | |
| this.wW = wW; | |
| this.hobby = hobby; | |
| this.hoW = hoW; | |
| } | |
| var PersonA = new ConditionsToLookFor( 150, 0.4, 50, 0.3, 'animals', 0.5); | |
| var PersonB = { | |
| height: 160, | |
| weight: 80, | |
| hobby: 'sports', | |
| } |
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
| calculateScore(PersonA, PersonB); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment