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

102
Views
Filtro de matriz 2D basado en clave hash

Salida: el usuario Ruby vio Transit y Max también vio la misma película y le dio una calificación superior a 3. Por lo tanto, la recomendación del usuario Ruby debe ser Max Jurassic Park y no un fin de semana.

¿Cómo obtengo la salida de abajo?

 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 answers
Answer question

0

Puede recopilar todas las relaciones usuario/película y película/usuario en dos tablas hash y obtener los usuarios que calificaron la misma película.

Obtenga de los usuarios las otras películas, tome solo películas únicas y filtre las calificadas.

 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 Report
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!