aceakash / string-similarity

Finds degree of similarity between two strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.
MIT License
2.53k stars 128 forks source link

Error: Bad arguments: First argument should be a string, second should be an array of strings #123

Open DancingPotatoes opened 2 years ago

DancingPotatoes commented 2 years ago

I am pretty sure I did it correctly I have the first as a string and the second as an array the code is

const pokemons = require('../../arrays/pokemons.js')
const poss = stringSimilarity.findBestMatch(args, pokemons)

arrays file

exports.pokemons = [
    pokemon lists
]
alvaroaac commented 2 years ago

This is very hard to debug. What's in args? Can you give an example of the pokemon lists?

spuggle commented 2 years ago

What you've done here is assigned your array to the pokemons property on the exports object:

exports.pokemons = [
  pokemon lists
]

When importing a module, it's export object is what you receive, so you'll need to access the pokemons property from the imported object to actually get the array you intended to work with. So you'll want something like (for ES6+):

const { pokemons } = require('../../arrays/pokemons.js')
const poss = stringSimilarity.findBestMatch(args, pokemons)
hoangvu12 commented 2 years ago

How is this an issue? The is skill problem. The author don't understand how exports work.