File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
6
- makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ makeCacheMatrix <- function (dataMatrix = matrix ()) {
7
+ inv = NULL
8
+ setFunc = function (newVal ) {
9
+ dataMatrix <<- newVal
10
+ inv <<- NULL
11
+ }
12
+ getFunc = function () dataMatrix
13
+ setInverseFunc = function (inverse ) inv <<- inverse
14
+ getInverseFunc = function () inv
15
+ list (set = setFunc , get = getFunc ,
16
+ setInverse = setInverseFunc , getInverse = getInverseFunc )
8
17
}
9
18
10
19
11
20
# # Write a short comment describing this function
12
21
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
22
+ cacheSolve <- function (matrixWrapper , ... ) {
23
+ inverse = matrixWrapper $ getInverse()
24
+ if (! is.null(inverse )) {
25
+ message(" getting cached data" )
26
+ return (inverse )
27
+ }
28
+ message(" calculating data" )
29
+ dataMatrix = matrixWrapper $ get()
30
+ inverse = solve(dataMatrix )
31
+ matrixWrapper $ setInverse(inverse )
32
+ inverse
15
33
}
You can’t perform that action at this time.
0 commit comments