더 좋은 코드를 위해 개발자는 문제해결 능력을 키워야한다. 선천적인 재능이 있다면 좋겠지만 없다 할지라도 좋은 로직과 코드들을 적어보고 접한다면 발전할 수 있지 않을까 희망해본다.
const twoSum = (nums, target) => {
let result =[];
for(let i in nums){
for(let j in nums){
if(nums[i]+nums[j]===target){
result.push(Number(i),Number(j));
return result
}
}
}
};
function twoSum(nums, target) {
for (let i = 0; i < nums.length-1; i++) {
for (let j = i+1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
return [i, j];
}
}
}
}
오늘도 반성합니다 컴퓨터님