
如何实现javascript函数来计算给定句子中每个单词的频率.
这是我的代码:
function search () {
var data = document.getElementById('txt').value;
var temp = data;
var words = new Array();
words = temp.split(" ");
var uniqueWords = new Array();
var count = new Array();
for (var i = 0; i < words.length; i++) {
//var count=0;
var f = 0;
for (j = 0; j < uniqueWords.length; j++) {
if (words[i] == uniqueWords[j]) {
count[j] = count[j] + 1;
//uniqueWords[j]=words[i];
f = 1;
}
}
if (f == 0) {
count[i] …Run Code Online (Sandbox Code Playgroud) 大家好我有多个插入语句的问题,我需要插入许多记录.我已经用这种方式编写,但记录没有插入"userbill"表.帮我??
..这是代码:
SQLiteDatabase db = mySQLiteHelper.getWritableDatabase();
String sql = "insert into userbill (billid, userid, date, amount, bill_status) values (?, ?, ?, ?, ?)";
db.beginTransaction();
SQLiteStatement st = db.compileStatement(sql);
try{
for(int i=0;i<Userid.length;i++)
{
st.bindLong(1, billid);
st.bindString(2, Userid[i]);
st.bindString(3, due_date);
st.bindDouble(4, amount/Userid.length);
st.bindString(5, "Due");
long entryID = st.executeInsert();
st.clearBindings();
}
db.setTransactionSuccessful();
}
catch(Exception e)
{
//e.printStackTrace();
Log.e("MYAPP", "exception", e);
}
finally
{
db.endTransaction();
}
db.close();
Run Code Online (Sandbox Code Playgroud)
logcat的:
09-05 13:12:48.610:D/dalvikvm(7982):GC_FOR_ALLOC释放314K,10%免费5030K/5568K,暂停17ms,总计18ms
09-05 13:12:48.610:I/dalvikvm-heap(7982):将堆(frag case)增长到6.181MB,用于1127532字节分配
09-05 13:12:48.614:D/dalvikvm(7982):GC_FOR_ALLOC释放2K,9%免费6129K/6672K,暂停5ms,总计5ms
09-05 13:12:48.710:W/EGL_genymotion(7982):eglSurfaceAttrib未实现
09-05 13:12:57.014:I/SQLiteConnectionPool(7982):/data/data/com.perfect12.app2maintain/databases/AMTDB的连接池已关闭,但仍有1个连接正在使用中.当他们被释放回游泳池时,他们将被关闭.
09-05 13:12:57.286:W/EGL_genymotion(7982):eglSurfaceAttrib未实现