Skip to content

Commit d15a02a

Browse files
committed
initial working code
1 parent 7f657dd commit d15a02a

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cachematrix.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33

44
## Write a short comment describing this function
55

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)
817
}
918

1019

1120
## Write a short comment describing this function
1221

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
1533
}

0 commit comments

Comments
 (0)