Skip to content

Instantly share code, notes, and snippets.

@lingoslinger
Last active September 15, 2023 23:41
Show Gist options
  • Save lingoslinger/bfb2af83396a98a0184db747138f21b6 to your computer and use it in GitHub Desktop.
Save lingoslinger/bfb2af83396a98a0184db747138f21b6 to your computer and use it in GitHub Desktop.
Swift: Merge two sorted arrays into a single sorted array
// I publicly share any answers to "coding challenges" I receive as a part of the interview process
// copy/paste this into an Xcode playground or the code challenge repl of choice
// the problame did not say what kind of elements are in these arrays, so time to get generic!
// assume both arrays contain the same type of elements
func mergeArraysAndSort<T: Comparable>(_ array1: [T], _ array2: [T]) -> [T] {
let merged = array1 + array2
return merged.sorted()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment