|
7 | 7 | # write guard clause against x != matrix
|
8 | 8 | # fix indentation to 4
|
9 | 9 | makeCacheMatrix <- function(x = matrix()) {
|
10 |
| - inverse <- NULL |
11 |
| - set <- function(y) { |
12 |
| - x <<- y |
13 |
| - inverse <<- NULL |
14 |
| - } |
15 |
| - get <- function() x |
16 |
| - setInverse <- function(inverseMatrix) inverse <<- inverseMatrix |
17 |
| - getInverse <- function() inverse |
18 |
| - list(set = set, get = get, |
19 |
| - setInverse = setInverse, |
20 |
| - getInverse = getInverse) |
| 10 | + inverse <- NULL |
| 11 | + set <- function(y) { |
| 12 | + x <<- y |
| 13 | + inverse <<- NULL |
| 14 | + } |
| 15 | + get <- function() x |
| 16 | + setInverse <- function(inverseMatrix) inverse <<- inverseMatrix |
| 17 | + getInverse <- function() inverse |
| 18 | + list(set = set, get = get, |
| 19 | + setInverse = setInverse, |
| 20 | + getInverse = getInverse) |
21 | 21 | }
|
22 | 22 |
|
23 | 23 |
|
24 | 24 | ## Write a short comment describing this function
|
25 | 25 |
|
26 | 26 | cacheSolve <- function(x, ...) {
|
27 |
| -## Return a matrix that is the inverse of 'x' |
28 |
| - |
29 |
| - inverse <- x$getInverse() |
30 |
| - if(!is.null(inverse)) { |
31 |
| - message("getting cached inverse matrix") |
| 27 | + ## Return a matrix that is the inverse of 'x' |
| 28 | + |
| 29 | + inverse <- x$getInverse() |
| 30 | + if(!is.null(inverse)) { |
| 31 | + message("getting cached inverse matrix") |
32 | 32 | return(inverse)
|
33 |
| - } |
34 |
| - |
35 |
| - data <- x$get() |
36 |
| - inverse <- solve(data, ...) |
37 |
| - x$setInverse(inverse) |
38 |
| - inverse |
| 33 | + } |
| 34 | + |
| 35 | + data <- x$get() |
| 36 | + inverse <- solve(data, ...) |
| 37 | + x$setInverse(inverse) |
| 38 | + inverse |
39 | 39 | }
|
0 commit comments