문제

I have an collection c, I basically want to split the collection into two parts: the first n items into one list and the rest to another. Obviously, I can use do:, but is there a better way to do it?

도움이 되었습니까?

해결책

I don't know about the other dialects but has this useful methods: first: last: allButFirst: allButLast:

So you can do something like:

firstPart := c first: 10.
secondPart := c allButFirst: 10

다른 팁

You can use copyFrom: to:.

For example:

firstTen := myCollection copyFrom: 1 to: 10.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top