Five-star scoring algorithms

//this.movies came back-end data
     let movies = data.data.modules[4].data.subject_collection_boards[0].items
// define array length
  let count=5;
//this.movies data from the back-end of each wondering if there's scores
  for (var i = 0; i < movies.length;i++){
    // define an array of stars used to store pictures
    imglist = [];
  // If there are scores (10 points, for example)
  if (movies[i].rating){
    // Define score score
    let score = (movies[i].rating.value)/2;
    // Is there a decimal (take the remainder is not 0)
    let scoresmall = score%1 !==0
    // score for the rounding process bright stars (Liang number (bright stars))
    let liang=Math.floor(score);
     // loop processing, the number of bright stars will push into the resulting array
    for (var a = 0; a < liang;a++){
    imglist.push("../../image/a.png")
   }
  // If there is a decimal, you push a half stars
  if (scoresmall){
    imglist.push("../../image/c.png")
  }
  // If the result is less than a preset maximum array length, dark stars would push into the resulting array
  while (imglist.length < count) {
    imglist.push("../../image/b.png")
  }
  // custom data transmitted from the rear end of a property equal imglist imgslist
  movies[i].imgslist = imglist
 
  }
}

Guess you like

Origin www.cnblogs.com/Angiy/p/11456044.html