Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
2D Array Filter based on hash key

Output: User Ruby watched Transit and Max also watched the same movie and gave rating above 3. So User ruby recommendation has to be Max Jurassic Park and not weekend away userRecommend("Ruby", ratings) => ["Jurassic Park"]

How do i get the ouput for below?

const userRating = [
['David', 'Weekend Away' , 5],
['Shell', 'Frozen', '5'],
['Max', 'Jurassic Park', '5'],
['Ruby', 'Transit', '4'],
['Ruby', 'Inception', '4'],
['Max', 'Transit', '5']
['Max', 'Weekend Away', '1']
]

const userRecommendation = (user, userRating) =>{


const hash = {};
for(let i=0; i< userRating.length; i++){
    if(userRating[i][2] >=4){
      if(!hash[userRating[i][0]]){
     hash[userRating[i][0]] = [userRating[i][1]];
      }else {
 hash[userRating[i][0]].push(userRating[i][1]);
      }
      
  }
}
let userMovie = hash[user];
 
let result =[];
for(let key of Object.keys(hash)){
  
  // Need to find a way to filter
  
}


}
console.log(userRecommendation('Ruby', userRating));
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could collect all user/movie and movie/user relations in two hash tables and get the users who have rated the same movie.

The get from the users the other movies, take only unique movies and filter the rated out.

const
    userRecommendation = (user, ratings) => {
        const
            users = {},
            movies = {},
            result = [];
            
        for (const [u, m, r] of ratings) {
            if (r < 4) continue;
            (users[u] ??= []).push(m);
            (movies[m] ??= []).push(u);
        }

        for (const movie of users[user]) {
            for (const u of movies[movie]) {
                if (u !== user) result.push(...users[u]);
            }
        }
        
        return [...new Set(result)].filter(m => !users[user].includes(m));
    },
    userRating = [['David', 'Weekend Away', 5], ['Shell', 'Frozen', 5], ['Max', 'Jurassic Park', 5], ['Ruby', 'Transit', 4], ['Ruby', 'Inception', 4], ['Max', 'Transit', 5], ['Max', 'Weekend Away', 1]];

console.log(userRecommendation('Ruby', userRating));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda