Answer the question
In order to leave comments, you need to log in
How to return a function value in node.js?
index.js
file
var mymodule = require('./mymodule');
var testword = require('./testword.json');
for( var word in testword){
var result = testword[word];
console.log('word: ', word, 'result: ', result);
}
module.exports.test = function (word) {
if(word.indexOf('a')+1){
return true;
}
else{
return false;
}
};
{
"yandex": true,
"google": true,
"huyandex": false
}
Answer the question
In order to leave comments, you need to log in
It's not really clear what you're doing at all, but probably something like this:
var tester = require('./mymodule').test,
assertions = require('./testword.json');
for (var word in testword) {
var expected = assertions[word],
actual = tester(word);
console.assert(actual === expected, actual, expected);
}
word.indexOf('a')+1
will pass for any word that has an "a" in it. And there is such a letter in both tested words, so the test is obviously wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question