Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 016bbbe

Browse files
committed
verify an existing inverse exists
1 parent d3a09cf commit 016bbbe

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cachematrix.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ makeCacheMatrix <- function(a_matrix = matrix()) {
3333
## Write a short comment describing this function
3434

3535
cacheSolve <- function(a_matrix, ...) {
36+
# get the cached inverse, assuming it exists
3637
inverse <- a_matrix$getinverse()
38+
# test the assumption
39+
if(!is.null(inverse)) {
40+
message("getting cached data")
41+
return(inverse)
42+
} else {
43+
message("No cached data!!")
44+
}
3745
## Return a matrix that is the inverse of 'a_matrix'
38-
inverse
46+
#inverse
3947
}

0 commit comments

Comments
 (0)