-
Notifications
You must be signed in to change notification settings - Fork 0
/
88_MergeSortedArrays.js
52 lines (45 loc) · 1.1 KB
/
88_MergeSortedArrays.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const assert = require('assert');
/**
* @param {number[]} nums1
* @param {number} m
* @param {number[]} nums2
* @param {number} n
* @return {void} Do not return anything, modify nums1 in-place instead.
*/
var merge = function(nums1, m, nums2, n)
{
// Handle crap inputs:
if (nums1 == undefined || nums2 == undefined)
{
return;
}
// Replace the last n values of nums1 with the nums2 values:
for (let i = m; i < (m + n); i++)
{
nums1[i] = nums2[i - m];
}
// Sort in ascending order:
nums1 = nums1.sort(function(a,b){
if (a > b)
{
return 1;
}
else if (a < b)
{
return -1;
}
else
{
return 0;
}
});
};
describe('88_MergeSortedArrays.js', function ()
{
it('should output to console Results nums1: [1,2,3,2,5,6]', function ()
{
var results = merge([1,2,3,0,0,0], 3, [2,5,6], 3);
// Does not return a result, based on description of problem, view output
assert.deepEqual(undefined, results);
});
});