JSFiddle - React, Tailwind, and code Playground
by 1eddy87
JavaScript
let nums = [3, 3];
let target = 6;
// let nums = [2, 7, 11, 15];
// let target = 9;
function test(nums, target) {
let result = [];
for (let i = 0; i < nums.length; i++) {
let diff = target - nums[i];
}
}
/*
function test(nums, target) {
for (var i = 0; i < nums.length; i++) {
var result = [];
result.push(i);
for (var j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target && i !== j) {
result.push(j);
console.log(result);
return result;
}
}
}
}
*/
test(nums, target);