-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e27496
commit f1d0eea
Showing
2 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import poketypejson from "../static/json/pokemon-types.json" | ||
|
||
function getPokeMatrix (pokeRange) { | ||
let pokeMatrix = [] | ||
let pokeMatrix2 = [] | ||
|
||
//TODO: look up faster way to initialize matrix | ||
for (const i in poketypejson) { | ||
pokeMatrix[i] = [] | ||
pokeMatrix2[i] = [] | ||
for (const j in poketypejson) { | ||
pokeMatrix[i][j] = 0 | ||
pokeMatrix2[i][j] = [] | ||
} | ||
} | ||
|
||
|
||
// create input data: a square matrix that show links between types | ||
for (let poke of pokeRange) { | ||
if (poke.type.length === 1) { | ||
const index0 = poketypejson.findIndex( | ||
type => type.name === poke.type[0] | ||
) | ||
pokeMatrix[index0][index0]++ | ||
pokeMatrix2[index0][index0].push(poke) | ||
} else { | ||
const index1 = poketypejson.findIndex( | ||
type => type.name === poke.type[0] | ||
) | ||
const index2 = poketypejson.findIndex( | ||
type => type.name === poke.type[1] | ||
) | ||
pokeMatrix[index1][index2]++ | ||
pokeMatrix[index2][index1]++ | ||
pokeMatrix2[index1][index2].push(poke) | ||
pokeMatrix2[index2][index1].push(poke) | ||
} | ||
} | ||
|
||
return { pokeMatrix, pokeMatrix2 } | ||
} | ||
|
||
export { getPokeMatrix } |