Skip to content

Conversation

@jinvicky
Copy link

@jinvicky jinvicky commented Sep 17, 2023

한 문제밖에 못 풀었지만 풀리퀘 올립니다ㅜㅜ
문제 풀 때 while(!iterator.next().done) {} 식으로 해서 done이 true가 아닐때 까지 돌게 하고 싶었는데 그게 생각대로 동작을 안하더라고요...

다른 문제들은 이해는 했는데 요세푸스 문제를 이해를 못했습니다...

담주는 좀 더 많이 풀어서 내겠습니다..
image

image

Comment on lines +37 to +44
const iterator = bag[Symbol.iterator]();
let size = numbers.length;
let result = 0;

while (size != 0) {
result += iterator.next().value;
size--;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

이터레이터를 직접 얻어서 구현해주셨네요. 이터레이터의 내부 동작을 자세하게 알면 이렇게 구현해도 괜찮겠네요.
for of를 쓰면 이터러블을 소비하여 동작하게 되는데, 이렇게 구현해봐도 좋아요
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

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