##SCREENING QUESTIONS
Answers are in Ruby.
####Reverse an array of characters in place
array.reverse!
####Count the number of occurrences of a substring within a string
string.scan(substring).count
####Count the number of occurrences of a substring within a string using recursion
https://github.com/Calvyn82/order/blob/master/recursive_counter.rb
####Object Oriented Principles Implement the E-commerce problem defined in Appendix 1.
I did it in Ruby, so the Order objects are not strictly immutable. To make them immutable, you would have to call .freeze on them after they are created.
https://github.com/Calvyn82/order/tree/master/e_commerce
####SQL Query #1 Assuming the classes you implemented in the E-commerce problem above get persisted in a database, write a SQL statement to retrieve the order number of all orders containing items with “JAZZY” in the name. Assume any table/field names within reason.
So, it depends on how my association is established between the orders table and the items table on the database.
If I have a unique row for every item in every order, then it’s straightforward.
SELECT DISTINCT order_id FROM items WHERE name=”JAZZY”;
I would probably create an association table called something like order_items that would have rows that consist of a primary key, order_id, and item_id, along with foreign keys on the latter two. The class models in Rails would both have has_many :through relationships with one another.
The raw SQL query would look something like…
SELECT "orders".”id”
FROM "orders"
INNER JOIN "order_items" ON "order_items"."order_id" = "orders"."id"
INNER JOIN "items" ON "items"."id" = "order_items"."item_id"
WHERE "items"."name" = $1 [["name", "JAZZY"]];
####SQL Query #2
Assuming the classes you implemented in the E-commerce problem above get persisted in a database, write a SQL statement to retrieve the order number of all orders priced over $100.00. Assume any table/field names within reason.
SELECT * FROM orders WHERE order_total > 100.00;