function assignProducts(data, id) {
  var arr = [];
  if(id){
    var arr = [id];
    var category = data.filter(data => data._id == id)[0].category;
    var data = data.filter(products => products.category == category);
  }
  var data = sort([...new Set(data.map(x => x._id))])
  while(arr.length < 3){
    var r = data[Math.floor(Math.random() * data.length)];
    if(arr.indexOf(r) === -1) arr.push(r);
  }
  return arr;
}
// Function to find products from the catalog for each user
Function to find products from the catalog for each user
Function to find products from the catalog for each user
function assignProducts(data, id) {
  var arr = [];
  if(id){
    var arr = [id];
    var category = data.filter(data => data._id == id)[0].category;
    var data = data.filter(products => products.category == category);
  }
  var data = sort([...new Set(data.map(x => x._id))])
  while(arr.length < 3){
    var r = data[Math.floor(Math.random() * data.length)];
    if(arr.indexOf(r) === -1) arr.push(r);
  }
  return arr;
}
function assignProducts ( data , id ) { var arr = [ ] ; if ( id ) { var arr = [ id ] ; var category = data . filter ( data => data . _id == id ) [ 0 ] . category ; var data = data . filter ( products => products . category == category ) ; } var data = sort ( [ ... new Set ( data . map ( x => x . _id ) ) ] ) while ( arr . length < 3 ) { var r = data [ Math . floor ( Math . random ( ) * data . length ) ] ; if ( arr . indexOf ( r ) === - 1 ) arr . push ( r ) ; } return arr ; }
Function to find products from the catalog for each user
Function to find products from the catalog for each user