Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Ada
- C
- Clojure
- Clojure
- Clojure
- Clojure
- C++
- C++
- C#
- D
- Dart
- Dart
- Elixir
- Fortran
- Go
- Haskell
- JS
- Java
- Java
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Rust
- Rust
- Scala
for E of elements loop
E := E * c;
end loop;
for(int i = 0; i < elements_size; ++i) elements[i] *= c;
elements_size must be provided, as there is no general way to figure it out.
(map #(* c %1) elements)
(map #(* c %) elements)
(map (fn [e] (* c e)) elements)
(map (partial * c) elements)
for (auto &it : elements)
it *= c;
elements.Select(x => x*c)
elements = [for (var e in elements) e * c];
From Dart 2.3, using collection for
elements = elements.map((e) => e * c).toList();
elements = Enum.map(elements, &(&1 * c))
elements = elements * c
for i := range elements {
elements[i] *= c
}
It is idiomatic to write this explicit loop.
map (*c) elements
(*c) is a shorthand for the lambda (\e -> e * c)
elements = elements.map(x => x * c)
Haskell's idioms are the best!
uh languages without basic list processing operations are good too
please don't hit me
uh languages without basic list processing operations are good too
please don't hit me
elements = elements.stream()
.map(x -> x * c)
.toList();
(mapcar (lambda (n) (* n c))
elements)
local function map(t,fn)
for i,v in ipairs(t) do
t[i]=fn(v)
end
return t
end
local ret=map(elements,function(x) return x*c end)
array_map(function($v) use ($_c) {
return $v*$c;
}, $_elements);
for i := Low(elements) to High(elements) do
elements[i] := elements[i] * c;
Low() and High() are compiler intrinsics that give the lower and upper bounds of an array (arrays in Pascal need not be zero-based).
@elements = map {$_ * $c} @elements;
f = lambda x: x * c
elements = [*map(f, elements)]
elements = [c * x for x in elements]
This maps the lambda function that multiplies a number by c to the list elements , and overwrites the old list
for i, x in enumerate(elements):
elements[i] = x * c
elements.map { |el| el * c }
Constants start with a capital, so c would be C
elements.iter_mut().for_each(|x| *x *= c);
It is possible to multiply the elements of the vector in-place, assuming you own the vector, or that you have mutably borrowed it.
elements.map(_ * c)