- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.list.pl
More file actions
Latest commit
22 lines (16 loc) · 628 Bytes
/
Copy path5.list.pl
File metadata and controls
22 lines (16 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
% find the membership of X in the array.
member(X,[X|_]).% if X is head of the list that mean X is in this array, return true.
member(X,[_|T]):-member(X,T).% if X is not the head that means it can be in the next index of the array.
% So, we do recursive by call member(X,T) which is the first statement again.
/* compare to JavaScript
function isValueExist(value, arr) {
let X = value;
let array = arr;
let i;
for (i = 0; i < array.length; i++) {
if ( X === array[i]) return true;
}
return false;
}
console.log(isValueExist(2, [1,2,3])); // return true
*/