Skip to content

Array example Caesar isn't well suited #227

@wilzbach

Description

@wilzbach
  1. it either requires loops or ranges (both haven't explained before)
  2. it requires casting (or knowing how to omit that by defining to char variables)
  3. it requires knowledge about ASCII (which we would at least have to explain)
  4. it's non-idiomatic D, because we usually do stuff lazily

That being said, here's my "idiomatic" solution:

import std.array: array;
import std.algorithm: map;
return input.map!((x) => cast(char) (((x - 97) + shift) % 26 + 97)).array;

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions