Created
December 3, 2018 04:45
-
-
Save baodinh/e8e1914cc060de54df06abbec0fbb7ac to your computer and use it in GitHub Desktop.
// source https://jsbin.com
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var givenNumbers = [10,15,3,7] | |
var result = 17 | |
alert(checkSum(givenNumbers)) | |
function checkSum(numbers){ | |
let isFound = false; | |
for (i = 0; i < numbers.length - 1 ; i++){ | |
if(numbers[0] + numbers[i + 1] == result){ | |
isFound = true; | |
} | |
} | |
if(isFound){ | |
return isFound; | |
}else{ | |
numbers.shift(); | |
checkSum(numbers) | |
} | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
var givenNumbers = [10,15,3,7] | |
var result = 17 | |
alert(checkSum(givenNumbers)) | |
function checkSum(numbers){ | |
let isFound = false; | |
for (i = 0; i < numbers.length - 1 ; i++){ | |
if(numbers[0] + numbers[i + 1] == result){ | |
isFound = true; | |
} | |
} | |
if(isFound){ | |
return isFound; | |
}else{ | |
numbers.shift(); | |
checkSum(numbers) | |
} | |
}</script></body> | |
</html> |
This file contains hidden or 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
var givenNumbers = [10,15,3,7] | |
var result = 17 | |
alert(checkSum(givenNumbers)) | |
function checkSum(numbers){ | |
let isFound = false; | |
for (i = 0; i < numbers.length - 1 ; i++){ | |
if(numbers[0] + numbers[i + 1] == result){ | |
isFound = true; | |
} | |
} | |
if(isFound){ | |
return isFound; | |
}else{ | |
numbers.shift(); | |
checkSum(numbers) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment