File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -40,5 +40,29 @@ export default function QueryProcessor(query: string): string {
4040 }
4141 }
4242
43+ const squareAndCubeMatch = query
44+ . toLowerCase ( )
45+ . match ( / w h i c h o f t h e f o l l o w i n g n u m b e r s i s b o t h a s q u a r e a n d a c u b e : \s * ( .+ ) \? / ) ;
46+ if ( squareAndCubeMatch ) {
47+ const numbers = squareAndCubeMatch [ 1 ]
48+ . split ( "," )
49+ . map ( ( value ) => Number ( value . trim ( ) ) )
50+ . filter ( ( value ) => Number . isInteger ( value ) ) ;
51+
52+ const matchingNumbers = numbers . filter ( ( value ) => {
53+ if ( value < 0 ) {
54+ return false ;
55+ }
56+
57+ const squareRoot = Math . round ( Math . sqrt ( value ) ) ;
58+ const cubeRoot = Math . round ( Math . cbrt ( value ) ) ;
59+ return squareRoot * squareRoot === value && cubeRoot * cubeRoot * cubeRoot === value ;
60+ } ) ;
61+
62+ if ( matchingNumbers . length > 0 ) {
63+ return matchingNumbers [ 0 ] . toString ( ) ;
64+ }
65+ }
66+
4367 return "" ;
4468}
You can’t perform that action at this time.
0 commit comments