11// Extractor: finalfunction
22// Scans blocks (bottom-up) for the last code_inline or asciimath_block line
3- // matching f(x) = <expr>, then sets answerEl.value to the extracted expression.
4- export default function finalfunction ( raw , answerEl , blocks ) {
3+ // matching f(x) = <expr>, then returns the extracted expression.
4+ export default function finalfunction ( raw , blocks ) {
55 const fxPattern = / ^ f \( x \) \s * = \s * / ;
66 const fxPatternRaw = / ^ ` * f \( x \) \s * = \s * / ;
77
@@ -11,24 +11,20 @@ export default function finalfunction(raw, answerEl, blocks) {
1111 if ( block . type === 'code_inline' ) {
1212 const trimmed = block . raw . trim ( ) ;
1313 if ( fxPattern . test ( trimmed ) ) {
14- answerEl . value = trimmed . replace ( fxPattern , '' ) ;
15- answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
16- return ;
14+ return trimmed . replace ( fxPattern , '' ) ;
1715 }
1816 }
1917 if ( block . type === 'asciimath_block' ) {
2018 const lines = block . raw . split ( / \r ? \n / ) ;
2119 for ( let j = lines . length - 1 ; j >= 0 ; j -- ) {
2220 const trimmed = lines [ j ] . trim ( ) ;
2321 if ( fxPattern . test ( trimmed ) ) {
24- answerEl . value = trimmed . replace ( fxPattern , '' ) ;
25- answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
26- return ;
22+ return trimmed . replace ( fxPattern , '' ) ;
2723 }
2824 }
2925 }
3026 }
31- return ;
27+ return 'ERROR' ;
3228 }
3329
3430 // Fallback: raw-text parsing when blocks are unavailable.
@@ -37,9 +33,8 @@ export default function finalfunction(raw, answerEl, blocks) {
3733 for ( const line of lines ) {
3834 const trimmed = line . trim ( ) ;
3935 if ( fxPatternRaw . test ( trimmed ) ) {
40- answerEl . value = trimmed . replace ( / ^ ` * f \( x \) \s * = \s * | ` + $ / g, '' ) ;
41- answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
42- return ;
36+ return trimmed . replace ( / ^ ` * f \( x \) \s * = \s * | ` + $ / g, '' ) ;
4337 }
4438 }
39+ return 'ERROR' ;
4540}
0 commit comments