Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Expand Intervals by SaintDron
"use strict";
function expandIntervals(items) {
let result = [];
for (let v of items) {
for (let i = v[0]; i <= v[1]; i++) {
result.push(i);
}
}
return result;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:');
console.log(expandIntervals([[1, 3], [5, 7]]));
// These "asserts" are used for self-checking and not for an auto-testing
assert.deepEqual(expandIntervals([[1, 3], [5, 7]]), [1, 2, 3, 5, 6, 7]);
assert.deepEqual(expandIntervals([[1, 3]]), [1, 2, 3]);
assert.deepEqual(expandIntervals([]), []);
assert.deepEqual(expandIntervals([1, 2], [4, 4]), [1, 2, 4]);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Dec. 12, 2018