Advertisement
Guest User

Pokemon Quest: finding signature moves

a guest
Jul 19th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const moveUsers = {};
  2.  
  3. for (const pokemon of app.pokeData) {
  4.     for (const move of pokemon.moves) {
  5.         if (move in moveUsers) {
  6.             moveUsers[move].push(pokemon);
  7.         } else {
  8.             moveUsers[move] = [pokemon];
  9.         }
  10.     }
  11. }
  12.  
  13. for (const move in moveUsers) {
  14.     let commonAncestor = false;
  15.  
  16.     for (const pokemon of moveUsers[move]) {
  17.         const evolutions = app.components.pokedata.getEvolutions(pokemon);
  18.  
  19.         if (moveUsers[move].every( user => evolutions.includes(user) )) {
  20.             // found a common ancestor for all pokemon that learn this move
  21.             commonAncestor = true;
  22.             break;
  23.         }
  24.     }
  25.  
  26.     if (commonAncestor) {
  27.         moveUsers[move] = moveUsers[move].map( user => user.name );
  28.     } else {
  29.         // no common ancestor found. It's not a signature move.
  30.         delete moveUsers[move];
  31.     }
  32. }
  33.  
  34. return moveUsers;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement