Skip to content

Instantly share code, notes, and snippets.

@manzaloros
Created August 3, 2021 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manzaloros/818580f97d8a0307dee6d4db396a6629 to your computer and use it in GitHub Desktop.
Save manzaloros/818580f97d8a0307dee6d4db396a6629 to your computer and use it in GitHub Desktop.
Switching two arrays around
// 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