//We know that indexes are zero-based (i.e., the first array index is 0)
//I.e., the array [10, 20, 30, 40] has indexes 0, 1, 2 and 3
Let variable "len" = the length of the array
let variable "lastIndex" = "len" minus 1
Let variable "element" = get the element at index "lastIndex"
Return variable "element"
//Note, we've left "YOUR_CODE_HERE" for you to finish
//See examples on how to get an element at an index
var len, lastIndex, element
len = array.size()
lastIndex = len - 1
element = YOUR_CODE_HERE
return element
//Return the last element in the input array
let getLastFct = (array) => {
var len, lastIndex, element
len = array.size()
lastIndex = len - 1
element = YOUR_CODE_HERE
return element
}
var array, result
array = [10, 20, 30, 40]
result = getLastFct(array)
println(result)
Combine (copy-paste) into full solution:
//Return the last element in the input arraylet getLastFct = (array) => {
var len, lastIndex, element
len = array.size()
lastIndex = len - 1
element = YOUR_CODE_HERE
return element
}
//Try Itvar array, result
array = [10, 20, 30, 40]
result = getLastFct(array)
println(result)
Object Oriented Programming
(Chapter 801 FP)
Chapter 801 FPWalk-Through for Function Basics Drill A Problem 3