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
Put these operating systems in order according to the date they were released. (The first to be released would be
uysha [10]
1. ms-dos 1981
2. windows 2.0 1987
3. windows xp 2001
4. mac os 2001
5. windows 7 2009
8 0
3 years ago
PLEASE HELP ASAP i will mark brilliant
Ray Of Light [21]
1. Cyberbullying
2.Confide in an adult you trust, such as a teacher or a parent
3.It is easy to miscommunicate  and escalate the situation in an online environment

Cyberbully hurts people, so NEVER post something that could hurt someone's feelings

Hope this helps!
3 0
3 years ago
Read 2 more answers
What command is used to add a reflection or an outline to text
WARRIOR [948]

text effects, and typography.

6 0
3 years ago
You need to design a backup strategy. You need to ensure that all servers are backed up every Friday night and a complete copy o
cestrela7 [59]

Answer: (A) full backup

Explanation: A backup strategy is a term used to describe the various effective approach engaged in creating a backup for data or information.

A FULL BACK UP IS THE VARIOUS APPROACH AND SYSTEMS PUT IN PLACE BY A COMPUTER USER OR AN INFORMATION TECHNOLOGY EXPERT IN ORDER TO CREATE AN ADDITIONAL SAMPLE OR COPY OF AN INFORMATION OR A DATA IN S SINGLE BACKUP.

8 0
3 years ago
While a threat intelligence analyst was researching an indicator of compromise on a search engine, the web proxy generated an al
inna [77]

Answer: the corret answer C. The analyst has prefetch enabled on the browser in use.

Explanation:

The analyst has like an indicator which is prefetch enabled on the browser in use.

7 0
3 years ago
Other questions:
  • Which character must decide whether to support the assassins or avenge his friend's death?
    14·2 answers
  • HELP AS SOON IS A UNIT TEST WILL GIVE BRAINLIEST
    9·2 answers
  • What are the Positive and negative sites of the internet
    14·1 answer
  • What are two types of organizational structures designed to help an organization achieve its goals and objectives?
    11·2 answers
  • Finish the statement below to correctly describe the Defense Enrollment Eligibility Reporting System (DEERS). DEERS is a central
    6·1 answer
  • AYUDAAAA!!!!! URGENTE!!!!!!1<br> ¿para que sirve la "BIG DATA"?
    9·1 answer
  • What is the correct order for writing the 3 dimensions for a 3D object? Here are the 3 dimensions:
    15·1 answer
  • Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the ca
    11·1 answer
  • I need it in code please (python)
    15·2 answers
  • How to make a 'Sign in with replit' button in replit (Node.js) will make brainliest
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!