Q:

Write a JavaScript program to initialize an array containing the numbers in the specified range where start and end are inclusive with their common difference step

0

Write a JavaScript program to initialize an array containing the numbers in the specified range where start and end are inclusive with their common difference step.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const initialize_Array_With_Range = (end, start = 0, step = 1) =>
  Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);

console.log(initialize_Array_With_Range(5)); 
console.log(initialize_Array_With_Range(8, 3));  
console.log(initialize_Array_With_Range(6, 0, 2));  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now