Skip to content
Advertisement

Check if array Is235

I want to check if an array Is235. Is235 is an array that has an integer divisible by 2, another integer divisible by 3 and a third integer divisible by 5. The other integers in the array that aren’t divisible by either of 2, 3, or 5 when added to the integers divisible by 2, 3 and 5 should be equal to the total number of elements in the array. Return 1 if the array Is235, else return 0. Please note that array cannot contain negative integers or zero. I want to approach this in a brute force manner only, thanks for your help in advance. My wrong attempt –

JavaScript

My countOne and countTwo variables couldn’t count the integers as i taught it would.

Advertisement

Answer

Try this, I tested it and it works, you should use the remainder operator %:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement