Skip to content

Instantly share code, notes, and snippets.

@ChickenFur
Created November 26, 2019 02:58
Show Gist options
  • Save ChickenFur/bfc006333986bb832370d4a745920960 to your computer and use it in GitHub Desktop.
Save ChickenFur/bfc006333986bb832370d4a745920960 to your computer and use it in GitHub Desktop.
4 ts
var findMedianSortedArrays = (nums1: Array<number>, nums2: Array<number>) => {
const newArray = nums1.concat(nums2);
newArray.sort((a, b) => {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
if (a === b) {
return 0;
}
});
if (newArray.length % 2 === 0) {
return (
(newArray[newArray.length / 2 - 1] + newArray[newArray.length / 2]) / 2
);
} else {
return newArray[Math.floor(newArray.length / 2)];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment