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

  • برمجة جافاسكربت java script
  • برمجة

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.

الأجوبة

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));  
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...