string-similarity icon indicating copy to clipboard operation
string-similarity copied to clipboard

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

Open DancingPotatoes opened this issue 3 years ago • 3 comments

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
]

DancingPotatoes avatar Nov 18 '21 13:11 DancingPotatoes

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

alvaroaac avatar Nov 19 '21 12:11 alvaroaac

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)

spuggle avatar Dec 18 '21 13:12 spuggle

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

hoangvu12 avatar Mar 21 '22 09:03 hoangvu12