Skip to content
Advertisement

Javascript: Adding elements of multiple integer and integer ranges into an array without also adding the ranges themselves

GOAL: add all elements from an array of integers and arrays, each child array is a set of 2 integers denoting a start and end of a range.

HTML invocation:

JavaScript

I have the following JavaScript:

JavaScript

When I invoke the onclick JavaScript the output is:

JavaScript

Both the range passed and the elements constructed by the range() function are added to the final array, but I just want the elements, not the ranges, so output should be:

JavaScript

Advertisement

Answer

Here’s how you can handle numbers along with ranges.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement