Last active
April 11, 2019 21:16
-
-
Save leopolicastro/4e299c3bb652a50d435a65a825c0bf88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2. Fill in the missing line: | |
// return the index of the minimum element in an array -- find minimum value in array and return index | |
// [2, 4, 1, 5] | |
function minValueIndex(array) { | |
var min_index = -1; | |
var min_value = 0; | |
for (var i = 0; i < array.length; ++i) { | |
if (array[i] < min_value || min_index == -1) { | |
min_index = i; | |
min_value = array[i]; | |
} | |
} | |
return min_index; | |
} | |
console.log(minValueIndex([2, 1, 3, 0, 4])); | |
// 5. What is the difference between jQuery.get() and jQuery.ajax()? | |
```.get() is just shorthand for .ajax() but it abstracts some of the the configurations away by setting | |
typical default values for you. It also only allows GET requests, obviously... .ajax() is the most configurable | |
of the two and allows for any type of http request such as POST, PATCH and DELETE. ``` | |
// $('#logo'); // document.getElementById('logo'); // 6. Which of the two lines of code below is more efficient? | |
// Explain your answer. | |
```Depends on what type of efficiency. $('#logo') is shorter cleaner and therefore more efficient to write. | |
document.getElementById('#logo') is native to Javascript and doesn't require an external library or any | |
extra resources like Jquery so it is more efficient to run.```; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Does this do what the comment says it does? | |
# take two sorted lists, and return both combined in sorted order | |
def merge_two_sorted_lists(l1, l2) | |
rtn = [] | |
if l1[0] < l2[0] | |
rtn += l1 | |
end | |
rtn += l2 | |
return rtn | |
end | |
```ANSWER: No it doesn't``` | |
# 3. Fill in the missing line: | |
# method("dog", ["cat", "dog", "frog"]) | |
# => 1 | |
# method returns index of first matching element in an array | |
def first_index_of_element_in_array(element, array) | |
array.each_with_index do |array_element, i| | |
array_element == element ? return i : nil | |
end | |
return -1 | |
end | |
# 4. What is x at the end of this script? | |
matrix = Array.new | |
matrix.push ([1, 2, 3]) | |
matrix.push ([4, 5, 6]) | |
matrix.push ([7, 8, 9]) | |
x = matrix[0][2]+ matrix[2][1] | |
x = 11 | |
# 7. Fill in the missing line: | |
# function recursively reverses a string | |
def recursive_string_reverse(string) | |
if string.length <= 1 | |
return string | |
end | |
first_char = string[0] | |
last_chars = string[1..string.length] | |
[first_char].unshift(recursive_string_reverse(last_chars)).join | |
end | |
p recursive_string_reverse("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment