Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김태민
/
OpenSource_Project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
seungmi
2019-12-03 01:34:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
329df989c8b861e46cabb2c12ced8cd874deb2c8
329df989
1 parent
1777a0f7
checkbox기능 추가
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
10 deletions
app.js
app.js
View file @
329df98
...
...
@@ -57,21 +57,63 @@ app.post('/food/recommendation', function(req, res) {
var
price
=
req
.
body
.
price
;
var
shape
=
req
.
body
.
shape
;
var
kinds
=
req
.
body
.
kinds
;
var
list
=
{
food
:
[]
};
function
add
(
users
,
price
,
shape
,
kinds
,
list
,
callback
)
{
if
(
!
Array
.
isArray
(
shape
)
&&
shape
)
{
var
shape
=
[];
shape
.
push
(
req
.
body
.
shape
);
}
if
(
!
Array
.
isArray
(
kinds
)
&&
kinds
)
{
var
kinds
=
[];
kinds
.
push
(
req
.
body
.
kinds
);
}
// var len_shape=shape.length;
// var len_kinds=kinds.length;
var
set1
=
new
Set
();
var
set2
=
new
Set
();
var
set3
=
new
Set
();
function
add
(
users
,
price
,
shape
,
kinds
,
callback
)
{
for
(
var
foods
in
users
)
{
if
((
!
price
||
users
[
foods
][
'price'
]
==
price
)
&&
(
!
shape
||
users
[
foods
][
'shape'
]
==
shape
)
&&
(
!
kinds
||
users
[
foods
][
'kinds'
]
==
kinds
))
{
list
.
food
.
push
(
foods
);
if
(
shape
)
{
for
(
var
i
=
0
;
i
<
shape
.
length
;
i
++
)
{
if
(
users
[
foods
][
'shape'
]
==
shape
[
i
])
{
set1
.
add
(
foods
);
}
}
}
else
{
set1
.
add
(
foods
);
}
if
(
kinds
)
{
for
(
var
j
=
0
;
j
<
kinds
.
length
;
j
++
)
{
if
(
users
[
foods
][
'kinds'
]
==
kinds
[
j
])
{
set2
.
add
(
foods
);
}
}
}
else
{
set2
.
add
(
foods
);
}
if
(
!
price
||
(
price
&&
users
[
foods
][
'price'
]
<=
Number
(
price
)
+
5000
&&
users
[
foods
][
'price'
]
>=
Number
(
price
)
-
5000
))
{
set3
.
add
(
foods
);
console
.
log
(
users
[
foods
][
'price'
]);
}
// $('<li>').text(foods).appendTo('#users');
}
callback
(
list
);
console
.
log
(
shape
);
console
.
log
(
kinds
);
console
.
log
(
set1
);
console
.
log
(
set2
);
console
.
log
(
set3
);
// console.log('shapeleng:' + shape.length);
// console.log('kinds leng:' + kinds.length);
callback
(
set1
,
set2
,
set3
);
}
add
(
users
,
price
,
shape
,
kinds
,
list
,
function
(
list
)
{
add
(
users
,
price
,
shape
,
kinds
,
function
(
set1
,
set2
,
set3
)
{
let
difference1
=
new
Set
([...
set1
].
filter
(
i
=>
set2
.
has
(
i
)));
let
difference2
=
new
Set
([...
difference1
].
filter
(
i
=>
set3
.
has
(
i
)));
var
list
=
{
food
:
[...
difference2
]
};
fs
.
writeFile
(
'data/temp.json'
,
JSON
.
stringify
(
list
),
"utf8"
,
function
(
err
)
{
if
(
err
)
{
console
.
log
(
err
);
...
...
@@ -97,7 +139,7 @@ app.post('/food/recommendation', function(req, res) {
});
//readFile closed
}
});
//writeFile closed
});
//add closed
});
//add closed
}
});
//readFile closed
...
...
Please
register
or
login
to post a comment