Daily Coding: 1
by ajgreencodes
HTML
<html>
<head>
</head>
<body>
<p>Click the following button to see the function in action</p>
<input type = "button" onclick = "findNumbers([12, 15, 3, 7], 16)" value = "Get Numbers">
</body>
</html>
JavaScript
function findNumbers(listOfNumbers, k) {
let result = false
for (const n of listOfNumbers) {
let x = k > n ? k - n : n - k
let y = k > x ? k - x : x - k
console.log("First No: " + x + " Second No: " + y)
if (listOfNumbers.includes(x)
&& listOfNumbers.includes(y)) {
if (x === y) {
if (listOfNumbers.filter(f => f === x).length > 1) {
result = true
break
}
}
else {
result = true
break
}
}
}
console.log("Result is:" + result);
}