Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js

Idiom #294 Print a comma-separated list of integers

Given an array a containing the three values 1, 12, 42, print out
"1, 12, 42" with a comma and a space after each integer except the last one.

let s = a.join(', ')
console.debug(s)
let s = a.reduce((x, y) => `${x}, ${y}`)
console.debug(s)
with Ada.Text_IO;
declare
   A : array (1 .. 3) of Integer := (1, 12, 42);
begin
   for I in A'Range loop
      Ada.Text_IO.Put (A (I)'Image);
      if I /= A'Last then
         Ada.Text_IO.Put (", ");
      end if;
   end loop;
end;

New implementation...
< >
tkoenig