I’m new to JS. I’m trying to get the output from a function below with return
but somehow it didn’t work and only console.log()
works.
var merge = function(nums1, m, nums2, n) {
let hasil = [];
for (let i = 0; i <= m; i++) {
const element = nums1[i];
hasil.push(element);
}
for (let j = 0; j <= n; j++) {
const element2 = nums2[j];
hasil.push(element2);
}
let jawaban = hasil.sort();
console.log(jawaban)
return jawaban
};
merge([1, 2, 3], 1, [5, 9, 2], 2);
2
Answers
Just try to call
merge()
function and assign the return value to a new variable. Then print it.I think you can use Promise.