0

I want to create this block of code work in Dart

int pivot (List list ,[ int start = 0 , int end = list.length ] ) { return 1}

this work fine if I wrote syntax like this in JavaScript but when writing it in dart it gives me error that list used in list.length is not defined. How can I solve it especially if this function will be used as recursive function so that I can't defined the parameters out of it.

I am returning 1 here to simplify the function logic as I want to focus on the parameter problem.

  • `int pivot(List list, [int start = 0, int end = -1]) { if (end == -1) { end = list.length; } ... }` – jamesdlin Mar 02 '22 at 08:41
  • @jamesdlin Thanks a lot bro, creative solution as I need it only to work and it did, but my brain only comparing between it and JS so it didn't find out that solution. – Asem Saafan Mar 02 '22 at 09:02

0 Answers0