Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sharpen Your Saw PT2
var async = require('async');
var request = require("request");
var _ = require('lodash');
var key = "TZlKw4gd1qFQhA2CbMLa";
var urlBase = "http://thesaurus.altervista.org/service.php?language=en_US&output=json&key=" + key + "&word=";
var phrase = "may the force be with you";
var wordArray = phrase.split(" ");
async.mapSeries(wordArray, countWords,function (err, result) {
console.log(result);
});
function countWords (word, next) { request(urlBase + word, function (err, response, body) {
if (err){
return err;
}
var Obj = JSON.parse(body);
var list = _.pluck(Obj.response, "list");
var uniquewords = [];
_.each(list, function (syn) {
uniquewords = _.union(uniquewords, (syn.synonyms.split("|")));
});
next(null,{word:[word,uniquewords.length]});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment