silent,
var arr = [6, 20, 21];
var mas = [];
for(var i = 0, j = 3; i < arr.length; i++, j-=1) {
(j > 0) ? mas.push(arr[i] + '-' + arr[i+j]) : j = 3;
i+=j;
}
alert(mas)
var a = [6,20,21];
function fn(b) {
for (var d = [], c, a = 0; a < b.length; a++)
if (!c && (c = b[a]), void 0 !== b[a + 1] && 1 < b[a + 1] - b[a] || a == b.length - 1) d.push(c + (c == b[a] ? "" : " - " + b[a])), c = !1;
return d
};
alert(fn(a))