Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MIS21
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Owen Ilagan
MIS21
Commits
bb441714
Commit
bb441714
authored
Jun 16, 2016
by
Owen Ilagan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hashes exercise
parent
81b59891
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
hashes.rb
_class_exercises/hashes.rb
+65
-0
No files found.
_class_exercises/hashes.rb
0 → 100644
View file @
bb441714
# EXERCISE #4
data
=
{
'2010'
=>
{
'Anabelle'
=>
{
'output'
=>
80
,
'training'
=>
24
,
'salary'
=>
8384
},
'Benedict'
=>
{
'output'
=>
15
,
'training'
=>
34
,
'salary'
=>
7090
},
'Charlie'
=>
{
'output'
=>
81
,
'training'
=>
82
,
'salary'
=>
3482
},
'Dorothy'
=>
{
'output'
=>
63
,
'training'
=>
8
,
'salary'
=>
6057
}
},
'2011'
=>
{
'Anabelle'
=>
{
'output'
=>
67
,
'training'
=>
68
,
'salary'
=>
6858
},
'Benedict'
=>
{
'output'
=>
9
,
'training'
=>
49
,
'salary'
=>
9505
},
'Charlie'
=>
{
'output'
=>
48
,
'training'
=>
48
,
'salary'
=>
9987
},
'Dorothy'
=>
{
'output'
=>
25
,
'training'
=>
28
,
'salary'
=>
5002
}
},
'2012'
=>
{
'Anabelle'
=>
{
'output'
=>
33
,
'training'
=>
24
,
'salary'
=>
3580
},
'Benedict'
=>
{
'output'
=>
27
,
'training'
=>
54
,
'salary'
=>
2191
},
'Charlie'
=>
{
'output'
=>
11
,
'training'
=>
10
,
'salary'
=>
6340
},
'Dorothy'
=>
{
'output'
=>
93
,
'training'
=>
99
,
'salary'
=>
5454
}
},
'2013'
=>
{
'Anabelle'
=>
{
'output'
=>
31
,
'training'
=>
81
,
'salary'
=>
1450
},
'Benedict'
=>
{
'output'
=>
5
,
'training'
=>
42
,
'salary'
=>
5791
},
'Charlie'
=>
{
'output'
=>
35
,
'training'
=>
15
,
'salary'
=>
415
},
'Dorothy'
=>
{
'output'
=>
52
,
'training'
=>
98
,
'salary'
=>
2366
}
},
'2014'
=>
{
'Anabelle'
=>
{
'output'
=>
54
,
'training'
=>
32
,
'salary'
=>
9086
},
'Benedict'
=>
{
'output'
=>
8
,
'training'
=>
32
,
'salary'
=>
1750
},
'Charlie'
=>
{
'output'
=>
16
,
'training'
=>
74
,
'salary'
=>
9400
},
'Dorothy'
=>
{
'output'
=>
19
,
'training'
=>
52
,
'salary'
=>
7050
}
},
'2015'
=>
{
'Anabelle'
=>
{
'output'
=>
4
,
'training'
=>
37
,
'salary'
=>
3054
},
'Benedict'
=>
{
'output'
=>
81
,
'training'
=>
83
,
'salary'
=>
2808
},
'Charlie'
=>
{
'output'
=>
33
,
'training'
=>
36
,
'salary'
=>
5547
},
'Dorothy'
=>
{
'output'
=>
53
,
'training'
=>
42
,
'salary'
=>
3677
}
}
}
def
get_average_salary_per_employee
(
data
)
result
=
Hash
.
new
years
=
0
data
.
each
do
|
key
,
yeardata
|
yeardata
.
each
do
|
employee
,
empdata
|
sum
=
result
[
employee
]
if
sum
.
nil?
sum
=
0
end
sum
+=
empdata
[
'salary'
]
result
[
employee
]
=
sum
end
years
+=
1
end
result
.
each
do
|
employee
,
salarydata
|
result
[
employee
]
/=
years
end
return
result
end
puts
"Average Salary Per Employee: "
+
get_average_salary_per_employee
(
data
).
to_s
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment