Last active
September 19, 2016 10:02
-
-
Save LewisGet/2388fd37bd16096ae2928a23faf4d12a to your computer and use it in GitHub Desktop.
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
var trainingUserData = [ | |
{age: 23, annualSalary: 30000, getCrad: true}, | |
{age: 17, annualSalary: 30000, getCrad: false}, | |
{age: 18, annualSalary: 35000, getCrad: true}, | |
// 讓金錢種要比例上升的資料 | |
/* 資料雜訊等到完成第一次版本後執行 | |
{age: 17, annualSalary: 830000, getCrad: true}, | |
{age: 17, annualSalary: 9830000, getCrad: true}, | |
*/ | |
{age: 18, annualSalary: 22000, getCrad: false}, | |
{age: 20, annualSalary: 22000, getCrad: false} | |
]; | |
var userData = {age: 20, annualSalary: 3000000}; | |
var userData2 = {age: 15, annualSalary: 3000000}; | |
var userData3 = {age: 33, annualSalary: 0}; | |
var w = {age: 0, annualSalary: 0}; | |
var training = function (trainingUserData, w) { | |
for (var i = 0; i < trainingUserData.lenght; i++) | |
{ | |
var thisData = trainingUserData[i]; | |
var thisDataKeys = Object.Keys(thisData); | |
for (var k = 0; k < thisDataKeys.lenght; k++) | |
{ | |
var thisTestKey = thisDataKeys[k]; | |
// 如果這筆資料 可以發卡 但 不是猜測的資料 | |
if (thisData[thisTestKey].getCrad && thisData[thisTestKey] !== w[thisTestKey]) | |
return {request: false, errorMessage: thisTestKey}; | |
// 如果這筆資料 不發卡 但是是猜測的資料 | |
if ((!thisData[thisTestKey].getCrad) && thisData[thisTestKey] == w[thisTestKey]) | |
return {request: false, errorMessage: thisTestKey}; | |
} | |
} | |
return {request: true}; | |
}; | |
for (;;) | |
{ | |
var pass = training(trainingUserData, w); | |
// 如果電腦沒通過 | |
if (! pass.request) | |
{ | |
w[pass.errorMessage] ++; | |
} | |
// 全部測驗通過了 | |
else | |
{ | |
console.log(w); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment