Skip to content

Instantly share code, notes, and snippets.

@chygoz2
Last active May 13, 2021 18:20
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 chygoz2/9b215f2ede3d6e0a5a3df1ad707eb8fc to your computer and use it in GitHub Desktop.
Save chygoz2/9b215f2ede3d6e0a5a3df1ad707eb8fc to your computer and use it in GitHub Desktop.
Algorithm Fridays 5 solution
const mergeAges = (classA: Array<number>, classB: Array<number>) => {
let mergedAges: Array<number> = []
let i = 0, j = 0
while(i < classA.length && j < classB.length) {
if (isNaN(classA[i]) || isNaN(classB[j])) throw new Error('Invalid input')
if (classA[i] <= classB[j]) {
mergedAges.push(classA[i++])
} else {
mergedAges.push(classB[j++])
}
}
if (i < classA.length) {
for (; i < classA.length; i++) {
if (isNaN(classA[i])) throw new Error('Invalid input')
mergedAges.push(classA[i])
}
}
if (j < classB.length) {
for (; j < classB.length; j++) {
if (isNaN(classB[j])) throw new Error('Invalid input')
mergedAges.push(classB[j])
}
}
return mergedAges
}
@meekg33k
Copy link

meekg33k commented May 13, 2021

Hello @chygoz2, thank you for participating in Week 5 of #AlgorithmFridays.

Congratulations! 🎉🎉, your solution has been selected as one of the 12 winning solutions for Week 5 of #AlgorithmFridays.

Your solution was selected because it is clean, robust, had the best time-efficiency and passes all of the test cases. I particularly like your error checks for each element in the array. Really clean!

However since only 3 solutions can be awarded the $20 prize, there will be a 'raffle draw' tomorrow at 9.00 am WAT (1.00 am PST) to select 3 out of the 12 solutions in a fair manner.

If you will to participate in the raffle draw, please send an email to uduak@meekg33k.dev or send me a DM on Twitter @meekg33k so I can share the meeting link with you.

Congratulations once again and thank you for participating you. See you tomorrow for Week 6 of #AlgorithmFridays.

@chygoz2
Copy link
Author

chygoz2 commented May 13, 2021

Thank you @meekg33k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment