On Saturday, 19 April 2014 at 17:12:10 UTC, Ali Çehreli wrote:
On 04/19/2014 09:55 AM, MattCoder wrote:
> On Friday, 18 April 2014 at 20:02:41 UTC, Tim Holzschuh via
> Digitalmars-d-learn wrote:
> void main(){
> int myfilter(int a){
> static int[] b;
That static variable makes thi
On Friday, 18 April 2014 at 22:11:17 UTC, bearophile wrote:
This preserves ordering and it's in-place. Not tested much:
void main() {
import std.stdio, std.traits;
auto data = [2, 1, 1, 3, 2, 3];
bool[ForeachType!(typeof(data))] seen;
size_t pos = 0;
foreach (immutable i; 0
On 04/19/2014 09:55 AM, MattCoder wrote:
> On Friday, 18 April 2014 at 20:02:41 UTC, Tim Holzschuh via
> Digitalmars-d-learn wrote:
> void main(){
> int myfilter(int a){
> static int[] b;
That static variable makes this solution non-reentrant. To see an effect
of this, replace the
On Friday, 18 April 2014 at 20:02:41 UTC, Tim Holzschuh via
Digitalmars-d-learn wrote:
Hi there,
I try to remove all equal elements of an array, thus [2,2] -->
[2].
I thought this maybe would be possible with
std.algorithm.reduce, but at least the way I tried it doesn't
work:
arr.reduce(
On Friday, 18 April 2014 at 22:11:17 UTC, bearophile wrote:
monarch_dodra:
Out of curiosity, if the requirement was to *also* preserve
ordering (eg: remove all non-first elements), how would you go
at it?
[2, 1, 1, 3, 2, 3] => [2, 1, 3];
Maybe std.algorithm's `makeIndex` would help here?
B
Am 18.04.2014 22:27, schrieb Steven Schveighoffer via Digitalmars-d-learn:
arr.sort();
arr = arr.uniq.array();
-Steve
Thanks, also for the explanation!
- Tim
monarch_dodra:
Out of curiosity, if the requirement was to *also* preserve
ordering (eg: remove all non-first elements), how would you go
at it?
[2, 1, 1, 3, 2, 3] => [2, 1, 3];
Maybe std.algorithm's `makeIndex` would help here?
Bonus points for doing it inplace.
This preserves ordering a
On Friday, 18 April 2014 at 20:27:20 UTC, Steven Schveighoffer
wrote:
Note also that what it returns is not an array, but a lazily
iterated range over the array. If you want another array, this
is the code I would use:
arr.sort();
arr = arr.uniq.array();
-Steve
Out of curiosity, if the requ
On Thu, 17 Apr 2014 09:46:25 -0400, Tim Holzschuh via Digitalmars-d-learn
wrote:
Hi there,
I try to remove all equal elements of an array, thus [2,2] --> [2].
I thought this maybe would be possible with std.algorithm.reduce, but at
least the way I tried it doesn't work:
arr.reduce( (a,b
Hi there,
I try to remove all equal elements of an array, thus [2,2] --> [2].
I thought this maybe would be possible with std.algorithm.reduce, but at
least the way I tried it doesn't work:
arr.reduce( (a,b) => a != b );
Is there a simple solution using Phobos-functions?
Thank you,
Tim
10 matches
Mail list logo