15
loading...
This website collects cookies to deliver better user experience
getPost(id) {
for (var i = 0; i < posts.length; i++) {
if (posts[i].id === id) {
return posts[i];
}
}
throw "No object with " + id + " id";
}
getPosts(filterConfig = "Date", skip = 0, top = posts.length) {
if (filterConfig == "Date") {
posts.sort(function (a, b) {
return new Date(b.createdAt) - new Date(a.createdAt);
});
return this.posts.slice(skip, top + skip);
}
else if (filterConfig == "summer") {
var temp = []
posts.forEach((product, ind) => {
if (product.tag == "summer"){
temp.push(product)
}
});
return temp
}
else if (filterConfig == "spring") {
var temp = []
posts.forEach((product, ind) => {
if (product.tag == "spring"){
temp.push(product)
}
});
return temp
}
else {
throw "Error. there is no such filter";
}
}
addPost(Object){
if(this.validatePost(Object)){
posts.splice(posts.length,0,Object);
return true;
}
else {
return false;
}
}
editPost(id,post){
if(this.validatePost(post)){
this.getPost(id).destination=post.destination;
this.getPost(id).author=post.author;
return true;
}else {
return false;
}
}
console.log("testing getPost: ")
console.log(a.getPost(3))
console.log("test removePost: ")
console.log(a.removePost("2"))
console.log("output all posts: ")
console.log(a.getPosts("Date"))
console.log(a.getPosts('spring'))
console.log(a.getPosts('summer'))