Created
May 18, 2020 15:16
-
-
Save jarvis-wu/bcd82cd2f94888dce42f08f6431c953a to your computer and use it in GitHub Desktop.
Answer a question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var axes = [String : (Double, Double)](); | |
| for question in shuffled { | |
| for valueYes in question.valuesYes { | |
| if axes[valueYes.axis] == nil { | |
| axes[valueYes.axis] = (0, 0) | |
| } | |
| if question.weightedAnswer > 0 { | |
| axes[valueYes.axis]?.0 += | |
| question.weightedAnswer * Double(valueYes.value) | |
| } | |
| axes[valueYes.axis]?.1 += Double(max(valueYes.value, 0)) | |
| } | |
| for valueNo in question.valuesNo { | |
| if axes[valueNo.axis] == nil { | |
| axes[valueNo.axis] = (0, 0) | |
| } | |
| if question.weightedAnswer < 0 { | |
| axes[valueNo.axis]?.0 -= | |
| question.weightedAnswer * Double(valueNo.value) | |
| } | |
| axes[valueNo.axis]?.1 += Double(max(valueNo.value, 0)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment