-4

As a reference to this question the idea is same

Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array

But

instead of deleting the duplicates I want them to show app

numArr=["hi", "apple", "window", "hi", "go", "window", "phone", "go", "hi", "down", "hi"];

At first I just wanna to know what function is that do find repeated items I think for python which I put hand on it is not that hard but seem here hard is javascript in addition I said I will try to find on google which do what I want but every code is harder to another code so before asking here I get a popular question which I provide the link above I just checked around but every code is harder then another so at that moment I decided to ask you here

and the result it show the same like this below

"hi","book","goal" appeared 4 times

"window","door","pencil","speaker" appeared 2 times

or I say every (number like four times appeared) make a new array look the easy if by number appeared or by order from a-z

notice that: - When I give to anyone he can pass his words and see his final result -I want the code to show in order from a-z and from big to small - the code or the function must accept even the words in array are million and above -even there is another words show same number of times display them.

jack
  • 11
  • 1
  • 2
    What have you tried so far? – Luca Kiebel Sep 12 '18 at 19:48
  • Hey Jack, you'll get a more positive reaction to questions like this if you show some code and explain where you are having trouble. Just posting a requirement about what the code must do sounds like you want a code-writing service — those kind of request are frowned upon here and lead to downvotes. – Mark Sep 12 '18 at 19:50
  • ok thhanks I will do that because I tried to know to do that but it is seem difficult – jack Sep 12 '18 at 19:57

1 Answers1

0

I'll give you the logic that you need, and invite you to take a crack at figuring out how to write the code. As several others have mentioned, we're not going to do it for you, but I'll be glad to see if I can teach you how to do it yourself.

First, create a two-dimensional array (i'll call it myResult). The first dimension will contain each distinct value from your numArr array. The second dimension will contain the total times that the value occurs in your array.

Now, use a for loop to iterate your array (means run through it from the beginning to the end). Each time you go through the loop, do these:

  1. Look in myResult for the value of the current array element (use findIndex(), so you can get the index of where it is).
  2. If you don't find it, add it to the array (use push()). Then, change the value of the second dimension to 1.
  3. If you do find it, just add 1 to the value of the second dimension (the first dimension's index will be the index you found using findIndex, while the second dimension's index will always be zero -- you're never going to have more than one total value for each of your array's values).

Once all that's done, you can iterate your myResult array and print your results (use console.log() to start; once you have it working the way you want you can work on getting it to print where you want it).

I suggest you read up and familiarize yourself with the methods I've recommended, and see if you can come up with your solution. If you have any questions, please ask in the comments. w3schools.com is an excellent place to start.

BobRodes
  • 5,990
  • 2
  • 24
  • 26
  • ok... It is helpful and it helped me to familiarize the methods to beused.... but I hope that I can see another answers which will help me – jack Sep 12 '18 at 20:31
  • @jack That sounds to me like you'd rather have someone do it for you than learn to do it yourself. When you're ready to make the attempt to do it yourself, I'll be glad to help you further if you need it. Feel free to ask specific questions about anything I've said if you need clarification. – BobRodes Sep 12 '18 at 20:45
  • @jack You're welcome. Now suppose you make an attempt to solve the problem. :) – BobRodes Sep 12 '18 at 20:48