7 kyu

Scoring Tests

1,398 of 3,418CajunAzn7

Description:

A new school year is approaching, which also means students will be taking tests.

The tests in this kata are to be graded in different ways. A certain number of points will be given for each correct answer and a certain number of points will be deducted for each incorrect answer. For ommitted answers, points will either be awarded, deducted, or no points will be given at all.

Return the number of points someone has scored on varying tests of different lengths.

The given parameters will be:

  • An array containing a series of 0s, 1s, and 2s, where 0 is a correct answer, 1 is an omitted answer, and 2 is an incorrect answer.
  • The points awarded for correct answers
  • The points awarded for ommitted answers (note that this may be negative)
  • The points deducted for incorrect answers (hint: this value has to be subtracted)

Note: The input will always be valid (an array and three numbers)

Examples

#1:

[0, 0, 0, 0, 2, 1, 0], 2, 0, 1  -->  9

because:

  • 5 correct answers: 5*2 = 10
  • 1 omitted answer: 1*0 = 0
  • 1 wrong answer: 1*1 = 1

which is: 10 + 0 - 1 = 9

#2:

[0, 1, 0, 0, 2, 1, 0, 2, 2, 1], 3, -1, 2)  -->  3

because: 4*3 + 3*-1 - 3*2 = 3

Arrays
Fundamentals

Stats:

CreatedAug 18, 2015
PublishedAug 18, 2015
Warriors Trained5428
Total Skips479
Total Code Submissions7319
Total Times Completed3418
JavaScript Completions1380
Python Completions1398
Haskell Completions164
Ruby Completions251
Java Completions303
C Completions67
COBOL Completions7
Total Stars41
% of votes with a positive feedback rating90% of 478
Total "Very Satisfied" Votes398
Total "Somewhat Satisfied" Votes69
Total "Not Satisfied" Votes11
Ad
Contributors
  • CajunAzn7 Avatar
  • jhoffner Avatar
  • g964 Avatar
  • anter69 Avatar
  • skleinbo Avatar
  • user5797210 Avatar
  • Voile Avatar
  • rowcased Avatar
  • eb110 Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
Ad