Dart solution
Here’s my solution to start the ball rolling. In the end I incorporated my part 1 answer into the part 2 logic, and golfed the code quite a lot.
import 'package:collection/collection.dart';
var ds = '0123456789'.split('');
var wds = 'one two three four five six seven eight nine'.split(' ');
int s2d(String s) => s.length == 1 ? int.parse(s) : wds.indexOf(s) + 1;
int value(String s, List digits) {
var firsts = {for (var e in digits) s.indexOf(e): e}..remove(-1);
var lasts = {for (var e in digits) s.lastIndexOf(e): e}..remove(-1);
return s2d(firsts[firsts.keys.min]) * 10 + s2d(lasts[lasts.keys.max]);
}
part1(List lines) => lines.map((e) => value(e, ds)).sum;
part2(List lines) => lines.map((e) => value(e, ds + wds)).sum;
It’s normally not so tricky on the first day, and the examples also normally do a much better job of guiding you away from wrong approaches so the increasing delay is intended to ensure you aren’t just spamming poorly tested answers.
The task in part two could be better written as “find the first occurrence of a digit in the string (either as a digit or as a word), and then separately find the last occurrence of a digit (either as a digit or as a word again) then compose these two digits”. Thinking of it like that should help you identify where your problem lies.