Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Created July 11, 2017 13:10
Show Gist options
  • Save SergProduction/b7998fa03fc02bcd181aabb2ced50068 to your computer and use it in GitHub Desktop.
Save SergProduction/b7998fa03fc02bcd181aabb2ced50068 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>brain</title>
</head>
<body>
<script type="text/javascript">
/*------example------
exampleInputData = [0,1,2,3,4,5,6]
exampleOutputData = [1,3,5]
pat = new fn(exampleInputData, exampleOutputData)
pat([11,12,13,14,15,16])
// [12,14,16]
*/
exampleInputData = [0,1,2,3,4,5,6,7]
exampleOutputData = [1,3,5,8]
function Brain(input, output){
const addition = (a, b) => a + b // сложение
const substraction = (a, b) => a - b // вычетание
const multiplication = (a, b) => a * b // умножение
const division = (a, b) => a / b // деление
var res = {
add:[],
sub: [],
mult: [],
div: []
}
function check(data, method, reverse) {
var result = []
for (let i=1; i<=data.length; i++){
var val = reverse
? method(data[i], data[i-1])
: method(data[i-1], data[i])
result.push({ iter:i ,val })
}
return result
}
res.add = check(input, addition)
res.sub = check(input, substraction)
res.mult = check(input, multiplication)
res.div = check(input, division)
return function(){
return res
}
}
var pattern = Brain(exampleInputData, exampleOutputData)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment