@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function () {
//1-5 为用户对书本的看法 0表示不参与对书籍喜爱
var db = {
"张三": { "悲惨的世界": 0, "济南的冬天": 3, "老舍的鹅": 1, "朱自清的背影": 3, "忘我": 5 },
"李四": { "悲惨的世界": 4, "济南的冬天": 0, "老舍的鹅": 3, "朱自清的背影": 4, "忘我": 5 },
"王五": { "悲惨的世界": 5, "济南的冬天": 3, "老舍的鹅": 0, "朱自清的背影": 2, "忘我": 5 },
"赵六": { "悲惨的世界": 0, "济南的冬天": 5, "老舍的鹅": 4, "朱自清的背影": 5, "忘我": 1 },
"钱七": { "悲惨的世界": 5, "济南的冬天": 5, "老舍的鹅": 1, "朱自清的背影": 1, "忘我": 2 },
"九通": { "悲惨的世界": 5, "济南的冬天": 3, "老舍的鹅": 5, "朱自清的背影": 4, "忘我": 1 },
"十刊": { "悲惨的世界": 0, "济南的冬天": 3, "老舍的鹅": 4, "朱自清的背影": 4, "忘我": 1 },
"十一孔": { "悲惨的世界": 0, "济南的冬天": 5, "老舍的鹅": 0, "朱自清的背影": 1, "忘我": 5 },
"十二簪": { "悲惨的世界": 5, "济南的冬天": 4, "老舍的鹅": 1, "朱自清的背影": 3, "忘我": 2 },
"十三甲": { "悲惨的世界": 5, "济南的冬天": 3, "老舍的鹅": 1, "朱自清的背影": 4, "忘我": 2 },
}
let ert = (Child, datadue) => {
let arrar = [];
let child = [];
let father = [];
for (key in Child)
child.push(Child[key])
for (key1 in datadue) {
let arrar_child = [];
for (key2 in datadue[key1])
arrar_child.push(datadue[key1][key2])
father.push(arrar_child)
}
for (let i = 0; i < father.length; i++) {
let len = 0;
for (let j = 0; j < child.length; j++) {
if (child[j] != 0 && father[i][j] != 0)
len += Math.abs(child[j] - father[i][j])
}
arrar.push(len);
}
return arrar;
}
console.log(ert(db["张三"], db));
//[0,3,1,11,7,9,8,4,4,4] 算出来的结论表示王五这个是最接近和张三的喜欢书的程度,之后将类似的人喜欢的书推荐给张三即可
// let qwe = (Child, datadue) => {
// let arrar = [];
// let child = [];
// let father = [];
// for (key in Child)
// child.push(Child[key])
// for (key1 in datadue) {
// let arrar_child = [];
// for (key2 in datadue[key1])
// arrar_child.push(datadue[key1][key2])
// father.push(arrar_child)
// }
// for (let i = 0; i < father.length; i++) {
// let len = 0;
// for (let j = 0; j < child.length; j++) {
// if (child[j] != 0 && father[i][j] != 0)
// len += Math.pow((child[j] - father[i][j]), 2)
// }
// arrar.push(Math.sqrt(len));
// }
// return arrar;
// }
// console.log(qwe(db["张三"], db));
})
</script>