通过这种简单但非常方便的方法来sample from an array without replacement,我们可以看到类似的
arr = ["a", "b", "c", "d", "e", "f"]
arr.sample(10)
=> ["b", "a", "d", "f", "e", "c"]
如何完成相同的任务,但 可以替换 ?因此,在示例.sample(10)
中将返回长度为10的数组,其中包含一些重复的元素吗?
例如
arr = ["a", "b", "c", "d", "e", "f"]
arr.sample(10)
=> ["b", "a", "d", "f", "e", "c", "b", "e", "a", "b"]
答案 0 :(得分:2)
采集1个样本10次并收集结果:
$(document).ready(function(){
var count=0;
$(document).on('click','#add',function() {
count++;
var html= '';
html += '<tr id="trrows">';
html += '<td id="testid"> <input id="test_id[]" class="form-control" type="text" style="width:200px" onblur="checkname();" onkeyup="checkname();" onchange="checkname();"> </td>';
html += '<td id="testname"> <input id="test_name" type="text" style="width:300px" class="form-control " readonly="" onblur="checkname();" onkeyup="checkname();" onchange="checkname();"> </td>';
html += '<td id="amounts"> <input id="amount" type="text" style="min-width:150px" class="form-control" readonly="" > </td>';
html += '<td><center> <a href="javascript:void(0)" class="text-danger font-18 remove" title="Remove" id="remove"><i class="fa fa-trash-o"></i></a></center> </td>';
html += '</tr>';
$('#rows').append(html);
});
$(document).on('click','.remove',function() {
$(this).closest("#trrows").remove();
});
});
// fetch test name from database
function checkname()
{
var test_id = document.getElementById("test_id[]").value;
$.ajax({
type: 'post',
url: "adminquery/fetch_test_name.php", // request file the 'check_email.php'
data: {'test_id': test_id,},
success: function (data) {
$("#test_name").val(data);
}
});
// fetch amount from database
var testid = document.getElementById("test_id[]").value;
$.ajax({
type: 'post',
url: "adminquery/fetch_test_name.php", // request file the 'check_email.php'
data: {'testid': testid, },
success: function (data) {
$("#amount").val(data);
}
});
}