Last active
September 15, 2023 23:41
-
-
Save lingoslinger/bfb2af83396a98a0184db747138f21b6 to your computer and use it in GitHub Desktop.
Swift: Merge two sorted arrays into a single sorted array
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
// 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