1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mrac [35]
2 years ago
8

Given an array of integers a, your task is to calculate the digits that occur the most number of times in the array. Return the

array of these digits in ascending order.
Computers and Technology
1 answer:
Annette [7]2 years ago
3 0

Answer:

I hope this should be helpful

Explanation:

In Javascript

function solution(numbers) {

   let hashmap = {};

   let ans = [];

   for (let i = 0; i < numbers.length; i++) {

     // check wether it double or single digit

     if (hasOneDigit(numbers[i])) {

       // check if it exists in hashmap

       // if exist add number of occurence

       // check if the occurence is greater than 2

       // add  if > 2 to the answer list

       if (numbers[i] in hashmap) {

         hashmap[numbers[i]] = hashmap[numbers[i]] + 1;

 

         if (hashmap[numbers[i]] = 2 && !ans.includes(numbers[i])) {

           // max_freq = hashmap[numbers[i]]

           ans.push(numbers[i]);

         }

         // else if (max_freq == hashmap[numbers[i]])

         //     ans = min(ans, numbers[i])

       } else {

         hashmap[numbers[i]] = 1;

       }

     } else {

       // change number to string

       number = numbers[i].toString();

       // loop to iterate every single element

       for (let j = 0; j < number.length; j += 1) {

 

         if (+number.charAt(j) in hashmap) {

           hashmap[+number.charAt(j)] = hashmap[+number.charAt(j)] + 1;

 

           if (hashmap[+number.charAt(j)] = 2 && !ans.includes(+number.charAt(j))) {

     

             ans.push(+number.charAt(j));

           }

       

         } else {

             hashmap[+number.charAt(j)] = 1

         }

       }

     }

   }

     return ans.sort();

 }

 

 function hasOneDigit(val) {

   return String(Math.abs(val)).charAt(0) == val;

 }

 console.log(solution([2, 1,42,44, 2, 3,32,7777, 3 , -1]));

 

You might be interested in
Write a program that reads three numbers and print the largest one step by step answer
const2013 [10]

Answer:

CLS

INPUT"Enter any three numbers";a,b,c

IF a>b AND a>c THEN

PRINT a;"is the greatest"

ELSEIF b>a AND b>c THEN

PRINT b;"is the greatest"

ELSE

PRINT c;"is the greatest"

ENDIF

END

6 0
2 years ago
How does the technology affect you daily living? Give situations where you use technology and how it helped you.​
Fiesta28 [93]

Answer:

Great!

Explanation:

I use mobile phone and i use it as exmergency phone

5 0
2 years ago
At which stage should James, a website designer, gather information about the website he wants to create, and at which stage sho
viva [34]
<h2>Answer: James should gather information in the <u><em>Learning</em></u> phase and begin the site’s coding in the <u><em>Development</em></u> phase.</h2>

8 0
3 years ago
Oliva was a sophomore thriving in college when her father was laid off from his job. Even with financial aid, the family could n
Zielflug [23.3K]

Answer:

Linked Lives

Explanation:

Linked-lives is a popular preposition, the idea is that people who are related to each like father-child or mother-child relationship have similar influencing trajetories of development that cuts across their lives.

6 0
3 years ago
Which of the following statements is true of licensing procedures for IT professionals?
melomori [17]

Answer:

the correct answer is b

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • HELP ASAP
    10·2 answers
  • Out of the following, find those identifiers, which cannot be used for naming Variables, Constants or Functions in a python prog
    11·1 answer
  • Assume that x is a string variable has been given a value. Write an expression whose value is true if and only if x is an hexade
    9·1 answer
  • Implement RandMultipByVal function, which gets one integervariable as its argument
    12·1 answer
  • How will you apply what you have learned in our topic today in a real life situation? Show your answers in the acronyms provided
    6·1 answer
  • How can you tell that a spreadsheet was saved as a 2007 Excel file?
    7·1 answer
  • Which components exist in the contextual tab for tables called Design? Check all that apply.
    15·2 answers
  • What does it mean to clear a setting in a dialog box?
    14·1 answer
  • Direction: Write True on the line if the statement is correct. Write False if the statement is incorrect. 1. All objects are com
    13·2 answers
  • Explain why computer professionals are engaged in technical services
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!