问题描述
我需要编写一个素数分解函数,该函数返回一个对象,该对象的键是素数,值是相应素数的指数。例如
console.log(primeFactorisation(4))// {2:2} console.log(primeFactorisation(6))// {2:1,3:1}
到目前为止,我的代码在下面,但我被卡住了。任何帮助表示赞赏。
const primeFactorisation = (num) => {
let result = {};
for (let i = 2; i < num; i++) {
if (num % i === 0) {
result[i] = i;
num /= i;
}
}
return result
}
解决方法
找到数字后,请在结果对象上递增数字,而不要为结果对象分配 <script>
$(document).ready(function(){
$('#myModal').on('show.bs.modal',function (e) {
var rowid = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',url : 'fetch_subjects.php',//Here you will fetch records
data : 'rowid='+ rowid,//Pass $id
beforeSend: function() {
$('.loader').show(); // Assuming that you have some loader defined
},success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
$('.loader').hide();
},});
});
});
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Subjects</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- loader -->
<div class="loader">
loading.............
</div>
<div class="fetched-data"> </div> <!--fetched dates here -->
</div>
<div class="modal-footer">
<button type="butZton" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
。
您还需要一个嵌套循环以继续测试数字,直到数字不再均分为止,并且还需要flutter build --verbose
,而不是i
,以便抓住最后一个因素:
i <= num