File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,20 @@ makeCacheMatrix <- function(local_matrix = matrix()) {
34
34
get_solved = get_solved )
35
35
}
36
36
37
- # # Write a short comment describing this function
38
-
39
- cacheSolve <- function (x , ... ) {
40
- # # Return a matrix that is the inverse of 'x'
37
+ # # Consumer of makeCacheMatrix
38
+ cacheSolve <- function (cache_matrix , ... ) {
39
+ # Get "solved" matrix
40
+ # If solution isn't cached it will be null
41
+ solution <- cache_matrix $ get_solved()
42
+ if (! is.null(solution )) {
43
+ # If solution is cached it will be returned
44
+ message(" Getting cached matrix" )
45
+ return (solution )
46
+ } else {
47
+ # Solve it...
48
+ solution <- solve(cache_matrix $ get_matrix(), ... )
49
+ # Put in cache just before return
50
+ cache_matrix $ set_solved(solution )
51
+ return (solution )
52
+ }
41
53
}
You can’t perform that action at this time.
0 commit comments