Skip to content

Commit a2ddd75

Browse files
committed
* Add a set function on the data structure.
1 parent 65de45b commit a2ddd75

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cachematrix.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ makeCacheMatrix <- function(x = matrix()) {
1919
# Intialize the cached value
2020
m <- NULL
2121

22+
# A function to reset the data
23+
# structure to a new matrix value
24+
set <- function(y) {
25+
x <<- y
26+
m <<- NULL
27+
}
28+
2229
# A function to get the given matrix
2330
get <- function() x
2431

@@ -30,7 +37,7 @@ makeCacheMatrix <- function(x = matrix()) {
3037

3138
# Return our data structure as a list, binding the
3239
# above functions to it
33-
list(get = get,
40+
list(set = set, get = get,
3441
setinverse = setinverse,
3542
getinverse = getinverse)
3643
}

0 commit comments

Comments
 (0)