0

Copy and create new array

function filterRange(arr, value1, value2) { var a; var b; var c; var j = 0; var arr1 = []; for (i = 0; i <= arr.length; i++) { if (arr[i] === value1) { a = i; } else if (arr[i] === value2) { b = i; }; }; if (b < a) { c = a; a = b; b = c; }; for (i = 0; a <= i <= b; i++) { arr1[j] = arr[i]; j++; }; return arr1; } var arr = [5, 4, 3, 8, 0]; var filtered = filterRange(arr, 3, 5); console.log(filtered); Help. Where is my mistake? Function not working.

12th Mar 2019, 4:37 PM
Andriy Halychanivskyi
Andriy Halychanivskyi - avatar
3 Réponses
+ 1
I made some corrections to your code. Hope it helps you. https://code.sololearn.com/Warr5KdKo19W/?ref=app
12th Mar 2019, 6:47 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Of course) Thanks friend.
12th Mar 2019, 7:18 PM
Andriy Halychanivskyi
Andriy Halychanivskyi - avatar
0
You are welcome 😉
12th Mar 2019, 7:42 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar