Logo

Programming-Idioms

Multiply all the elements of the list elements by a constant c
Implementation
Go

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Go implementation.

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.

Other implementations
elements[] *= c;
for i := Low(elements) to High(elements) do 
  elements[i] := elements[i] * c;
elements = [c * x for x in elements]
(map (partial * c) elements)
elements.map { |el| el * c }
map (*c) elements
for (auto &it : elements)
	it *= c;
let elements = elements.into_iter().map(|x| c * x).collect::<Vec<_>>();
elements = elements.map(x => x * c)
elements.map(_ * c)
elements = Enum.map(elements, &(&1 * c))
@elements = map {$_ * $c} @elements;
(mapcar (lambda (n) (* n c))
        elements)
elements.Select(x => x*c)
import java.util.stream.Collectors;
elements = elements.stream().map(e -> e*c).collect(Collectors.toList());
array_map(function($v) use ($_c) {
    return $v*$c;
}, $_elements);
elements = elements * c
#include <algorithm>
std::transform(std::begin(elements), std::end(elements), std::begin(elements), [c](auto i){
        return i*c;
    });
elements = [for (var e in elements) e * c];
elements = elements.map((e) => e * c).toList();
for E of elements loop
   E := E * c;
end loop;
elements.iter_mut().for_each(|x| *x *= c);