Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Created December 22, 2016 19:41
Show Gist options
  • Save cacheflow/b405715a2907e149bee3e21fd3837284 to your computer and use it in GitHub Desktop.
Save cacheflow/b405715a2907e149bee3e21fd3837284 to your computer and use it in GitHub Desktop.
function findSum(list, sum) {
let listCopy = list.slice(0).sort()
let start = 0
let end = list.length - 1
while(start <= end ) {
if(list[start] + list[end] == sum) {
return true
}
else if(list[start] + list[end] > sum) {
start += 1
}
else if(list[start] + list[end] < sum) {
end -= 1
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment