Skip to content

Commit 1d34bfe

Browse files
author
梶塚太智
committed
Refactoring
1 parent 514ff75 commit 1d34bfe

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/main.rs

Lines changed: 15 additions & 14 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,20 +1292,6 @@ impl Executor {
12771292
})
12781293
}
12791294

1280-
"index" => {
1281-
let findhint = self.pop_stack().get_string();
1282-
let findtarget = self.pop_stack().get_list();
1283-
1284-
for index in 0..(findtarget.len()) {
1285-
if findhint == findtarget[index].clone().get_string() {
1286-
self.stack.push(Type::Number(index as f64));
1287-
return;
1288-
}
1289-
}
1290-
self.log_print(String::from("Error! item not found in this list").as_str().to_owned() + "\n");
1291-
self.stack.push(Type::Error(String::from("item-not-found")));
1292-
}
1293-
12941295
// If it is not recognized as a command, use it as a string.
12951296
_ => self.stack.push(Type::String(command)),
12961297
}

0 commit comments

Comments
 (0)