Skip to content

Commit 8c6cc3f

Browse files
committed
makeCacheMatrix added
1 parent 7f657dd commit 8c6cc3f

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

cachematrix.R

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
# Hi! I'm the guy from Ruby Planet! And I love clear code.
2+
# It was painfull for me to read initial version, so I've refactored all names.
3+
# Please Enjoy R and this MOOC. If you are interested in detailed information
4+
# please read detailed comment at the end of code.
5+
# Thanks for your review!
36

4-
## Write a short comment describing this function
7+
makeCacheMatrix <- function(local_matrix = matrix()) {
8+
# By default local_matrix is the empty matrix
59

6-
makeCacheMatrix <- function(x = matrix()) {
10+
# Initializing variable supposed for cached solution
11+
cached_solution <- NULL
712

8-
}
13+
set_matrix <- function(arg) {
14+
local_matrix <<- arg
15+
cached_solution <<- NULL
16+
}
17+
get_matrix <- function() local_matrix
18+
19+
# Setting cached solution
20+
set_solved <- function(solution) cached_solution <<- solution
21+
# Getting cached solution
22+
get_solved <- function() cached_solution
923

24+
# Return list of functions list of functions:
25+
# - `set_matrix` - set the value of the matrix
26+
# - `get_matrix` - get the value of the matrix
27+
# - `set_solved` - set the value of the inverted matrix
28+
# - `get_solved` - get the value of the inverted matrix
29+
30+
list(
31+
set_matrix = set_matrix, # ...$set_matrix
32+
get_matrix = get_matrix, # ...$get_matrix
33+
set_solved = set_solved,
34+
get_solved = get_solved)
35+
}
1036

1137
## Write a short comment describing this function
1238

0 commit comments

Comments
 (0)