Created
August 3, 2021 12:17
-
-
Save manzaloros/818580f97d8a0307dee6d4db396a6629 to your computer and use it in GitHub Desktop.
Switching two arrays around
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you have a function working on two arrays: | |
const compareArrays = (nums1, nums2) => { | |
... | |
} | |
// And you need the larger or smaller array to be in a certain position, | |
// you can do: | |
const compareArrays = (nums1, nums2) => { | |
// invoke function making smaller array first in the order: | |
if (nums1.length > nums2.length) return compareArrays(nums2, nums1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment