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

Skip to content

Commit 76da95f

Browse files
committed
renaming of set_inverse and get_inverse. Removed underscore to match sample output from TAs in discussion forum
1 parent 5c3e431 commit 76da95f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cachematrix.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ makeCacheMatrix <- function(x = matrix()) {
1111
inverse_x <<- NULL
1212
}
1313
get <- function() x
14-
set_inverse <- function(inverse) inverse_x <<- inverse
15-
get_inverse <- function() inverse_x
14+
setinverse <- function(inverse) inverse_x <<- inverse
15+
getinverse <- function() inverse_x
1616
list(set = set, get = get,
17-
set_inverse = set_inverse,
18-
get_inverse = get_inverse)
17+
setinverse = setinverse,
18+
getinverse = getinverse)
1919
}
2020

2121

@@ -26,13 +26,16 @@ makeCacheMatrix <- function(x = matrix()) {
2626

2727
cacheSolve <- function(x, ...) {
2828
## Return a matrix that is the inverse of 'x'
29-
inverse_x = x$get_inverse()
29+
inverse_x <- x$getinverse()
30+
## Try to get inverse from cache
3031
if (! is.null(inverse_x)) {
31-
message("getting cached data")
32+
message("Got inverse from cache")
3233
return(inverse_x)
3334
}
35+
## Inverse not in cache, calculate with solve
3436
data <- x$get()
3537
inverse_x <- solve(data, ...)
36-
x$set_inverse(inverse_x)
38+
## Set inverse in cache
39+
x$setinverse(inverse_x)
3740
inverse_x
3841
}

0 commit comments

Comments
 (0)