Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to filter data of blogs to not add empty blogs or blogs with empty titles

Here's the controller:

import API from '../scripts/api.js' class Controller {

constructor(model, view) {
    this.model = model
    this.view = view
    this.author=window.location.search.substr(10), 
    this.view.handleShowForm()
}


//a function to  get the  data from the api
fetch() {
  API.readAll('https://blog-server-rbk.herokuapp.com/api/blogs',function (data) {
    console.log('data: data sent',data)
    this.model.addBlogs(data) ;


})
}

and the model class with the method addBlogs, the problem is there,that should add blogs to the state

  class Model {
constructor() {
    //a state of the model 
    this.blogs = []
}
 

//this function should filter to not add empty blogs
addBlogs(blogs) {
    blogs.filter(element => element.body.length==0 || element.title.length==0)
    this.blogs = blogs;
}

}

export default Model

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!