Question: I'm trying to implement a function to read files, but I cannot change the signature of the method. There are a lot of cross references in the code but maybe someone can enlighten me, I have been stuck for 3 days right now. This is for a school assignment.

The first method I'm trying to pass into the function is the following:

```
public static Purchase fromLine(String textLine, List<Product> products) {
        Purchase newPurchase = null;
        String[] purchases = textLine.split(",");
        int foundBarcode = products.indexOf(getProductFromBarcode(products, Long.parseLong(purchases[0])));

        products.indexOf(purchases);
        newPurchase = new Purchase(
                products.get(foundBarcode),
                Integer.parseInt(purchases[1].trim())
        );

```

Somehow I want to pass this function into my import file function.

```
    public static <E> void importItemsFromFile(List<E> items, String filePath, Function<String,E> converter) {
        int originalNumItems = items.size();

        Scanner scanner = createFileScanner(filePath);

        // TODO read all source lines from the scanner,
        //  convert each line to an item of type E and
        //  and add each item to the list

        while (scanner.hasNext()) {
            // input another line with author information
            String line = scanner.nextLine();

            // TODO convert the line to an instance of E
            E newItem = converter.apply(line);

            // TODO add the item to the list of items
            items.add(newItem);
        }
        System.out.printf("Imported %d items from %s.\n", items.size() - originalNumItems, filePath);
    }

```

I hope someone can help me and explain how to pass this function into the other function's converter parameter.
Tried to do a lot of research on this topic but I'm still not able to find the answer. Please help me stackoverflow community!:D

Answer: 
Just take a [`for ... of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of), because the array could have days in different order or start.

And for really good code, take a semantic name `day` instead of `i`.

```js
const weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

for (const i of weekDays) {
    if (i === 'Wednesday') {
        console.log('Today is Wednesday, join board meeting by 10:00am');
        continue;
    }
    if (i === 'Saturday') {
        console.log("Today is Saturday, weekend is great!");
        break;
    }
    console.log(i);
}
```
I know you provided your own answer, but this code could easily be cleaned up further to reduce bugs:

```js
for (let i = 0; i < weekDays.length; i++) {
    if (i === 3) {
        console.log('Today is Wednesday, join board meeting by 10:00am');
    } else if (i === 6) {
        console.log("Today is Saturday, weekend is great!");
    } else {
        console.log(weekDays[i]);
    }
}

```

Still not a fan of the magic numbers. Perhaps `i === Day.Wednesday` or `weekDays[i] === Day.Wednesday` depending on what's expected to change.