Instead of Ngrams, I am trying to achieve something like startsWith -for each word in a sentence.
For that, I am facing some problem in writing forLoop. Could you please help me.
function GenearateStartsWithKeywords(str) {
const myArr = [];
for (let i = 0; i < str.length; i++) {
myArr.push(str.substr(0, i + 1));
}
return myArr;
}
async function main(client) {
const fql = q.Let(
{
words: ["Jagadeesh", "Palaniappan"],
results: q.Map(
q.Var("words"),
q.Lambda("eachWord", GenearateStartsWithKeywords(q.Var("eachWord")))
),
},
q.Var("results")
);
const resp = await client.query(fql);
console.log(resp);
}
I am looking for the below output,
[
["J", "Ja", "Jag", "Jaga", "Jagad", "Jagade", "Jagadee", "Jagadees", "Jagadeesh"],
["P", "Pa", "Pal", "Pala", "Palan", "Palani", "Palania", "Palaniap", "Palaniapp", "Palaniappa", "Palaniappan"]
]
Could you please help me.