github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/hiddenPassion.go (about) 1 // Copyright 2021 Robert D. Wukmir 2 // This file is subject to the terms and conditions defined in 3 // the LICENSE file, which is part of this source code package. 4 // 5 // Unless required by applicable law or agreed to in writing, 6 // software distributed under the License is distributed on an 7 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 // either express or implied. See the License for the specific 9 // language governing permissions and limitations under the 10 // License. 11 12 package numerology 13 14 import ( 15 "sort" 16 ) 17 18 // HiddenPassionResults packages the key information from the Numbers function. 19 type HiddenPassionResults struct { 20 // Numbers is a slice of int of all the numbers that have the highest or equally highest count. 21 Numbers []int `json:"numbers"` 22 23 // MaxCount is the count of the highest number(s). 24 MaxCount int `json:"max_count"` 25 } 26 27 // hiddenPassions calculates the numerology number(s) that are repeated the most in the given name. 28 func hiddenPassions(counts map[int32]int) (results HiddenPassionResults) { 29 // Iterate over counts to find the numbers that match the largest count. 30 passions := []int{} 31 max := 0 32 for k, v := range counts { 33 if v > max { // If we find a new max then update the var and replace passions with new number. 34 max = v 35 passions = []int{int(k)} 36 } else if v == max { // If we find an equal to max then add the number to slice of passions. 37 passions = append(passions, int(k)) 38 } 39 } 40 sort.Ints(passions) 41 return HiddenPassionResults{passions, max} 42 }