File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -772,6 +772,21 @@ impl Executor {
772
772
self . stack . push ( Type :: List ( list) ) ;
773
773
}
774
774
775
+ // Get index of the list
776
+ "index" => {
777
+ let findhint = self . pop_stack ( ) . get_string ( ) ;
778
+ let findtarget = self . pop_stack ( ) . get_list ( ) ;
779
+
780
+ for index in 0 ..( findtarget. len ( ) ) {
781
+ if findhint == findtarget[ index] . clone ( ) . get_string ( ) {
782
+ self . stack . push ( Type :: Number ( index as f64 ) ) ;
783
+ return ;
784
+ }
785
+ }
786
+ self . log_print ( String :: from ( "Error! item not found in the list" ) . as_str ( ) . to_owned ( ) + "\n " ) ;
787
+ self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
788
+ }
789
+
775
790
// Sorting in the list
776
791
"sort" => {
777
792
let mut list: Vec < String > = self
@@ -1277,6 +1292,7 @@ impl Executor {
1277
1292
} )
1278
1293
}
1279
1294
1295
+ <<<<<<< HEAD
1280
1296
"index" => {
1281
1297
let findhint = self . pop_stack( ) . get_string( ) ;
1282
1298
let findtarget = self . pop_stack( ) . get_list( ) ;
@@ -1299,6 +1315,8 @@ impl Executor {
1299
1315
self . clearscreen( ) ;
1300
1316
}
1301
1317
1318
+ =======
1319
+ >>>>>>> 1 d34bfe ( Refactoring )
1302
1320
// If it is not recognized as a command, use it as a string.
1303
1321
_ => self . stack. push ( Type :: String ( command ) ) ,
1304
1322
}
You can’t perform that action at this time.
0 commit comments