Skip to content

Conversation

@MJbae
Copy link

@MJbae MJbae commented Dec 8, 2023

우선 1~3번, 6번 문제만 풀어보았습니다.

콜스택을 그려가며 문제를 풀다보니까 재귀의 동작에 대해 이해도가 높아졌습니다.
재귀와 꼬리재귀 그리고 동적계획법으로 이어지는 최적화의 과정이 재미있었습니다.

@MJbae MJbae closed this Dec 8, 2023
@MJbae MJbae reopened this Dec 8, 2023
// return acc;
// };

const solution = (numbers) => numbers.reduce((acc, cur) => acc + cur, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼬리 재귀 함수는 모두 reduce함수로 구현이 가능하다는 것을 이용해 구현하셨네요 ㅎㅎ 좋습니다

// break;
// }

// acc += numbers.pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numbers.pop()은 원본 배열을 수정하는 메서드입니다. 만약 다른 곳에서 numbers를 참조하고 있었다면 예상하지 못한 일이 일어날 수 있을 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요! 원본 데이터에 직접 접근하고 있네요! 감사합니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants