Skip to content

Commit ce3cc7e

Browse files
committed
git
1 parent 8df72ca commit ce3cc7e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,21 @@ impl Executor {
772772
self.stack.push(Type::List(list));
773773
}
774774

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+
775790
// Sorting in the list
776791
"sort" => {
777792
let mut list: Vec<String> = self
@@ -1277,6 +1292,7 @@ impl Executor {
12771292
})
12781293
}
12791294

1295+
<<<<<<< HEAD
12801296
"index" => {
12811297
let findhint = self.pop_stack().get_string();
12821298
let findtarget = self.pop_stack().get_list();
@@ -1299,6 +1315,8 @@ impl Executor {
12991315
self.clearscreen();
13001316
}
13011317

1318+
=======
1319+
>>>>>>> 1d34bfe (Refactoring)
13021320
// If it is not recognized as a command, use it as a string.
13031321
_ => self.stack.push(Type::String(command)),
13041322
}

0 commit comments

Comments
 (0)