Traverse a Nexo frequency range with a for loop and classify each number into exclusive or common multiples using the modulo operator (%).
JavaScriptBeginnerWith Nexo
bucles · condicionales · modulo
Statement
Your mission
During Nexo's digital signal calibration, two receiver channels scan a range of integer frequencies. Channel A detects multiples of multiploA, Channel B detects multiples of multiploB, and whenever a frequency matches both channels simultaneously, it is recorded as a synchronized signal in ambos.
Implement the solve(input) function, which receives a JSON object with four integer properties:
inicio: integer between 0 and 1000.
fin: integer between inicio and 1000.
multiploA: integer between 1 and 20.
multiploB: integer between 1 and 20.
Traverse all integers from inicio to fin (both inclusive) in ascending order and classify each number according to these mutually exclusive rules:
If it is divisible by both multiploA and multiploB, add it exclusively to the ambos array.
If it is divisible only by multiploA, add it to the soloA array.
If it is divisible only by multiploB, add it to the soloB array.
If it is not divisible by either, omit it.
Important notes:
The number 0 is a multiple of any positive divisor (0 % d === 0).
If multiploA and multiploB are equal, all of their multiples belong exclusively to ambos.
Return a JSON object with those exact six properties:
soloA: array of integers in ascending order.
soloB: array of integers in ascending order.
ambos: array of integers in ascending order.
cantidadSoloA: length of soloA.
cantidadSoloB: length of soloB.
cantidadAmbos: length of ambos.
Rules and constraints
Explicitly use a for loop and if / else if conditional structures. Using push() and length is allowed.
Do not use filter(), map(), reduce(), Array.from(), Set, recursion, classes, or helper functions.
No number may appear in more than one array at the same time.