Skip to content
Advertisement

Find how many numbers two numbers have in common

So I’m trying to make a program that tells the user how many numbers both inputted numbers have in common

FOR EXAMPLE: if inputted n1 = 765 and n2 = 572 then the program returns 2 because both numbers have 7 and 5 in them.

I made this but it isn’t working:

JavaScript

Advertisement

Answer

Use list comprehension and sets instead, like so:

JavaScript
Advertisement