I am attempting to insert a dash between even numbers in an array taken from an input. My approach involves using the reduce() method combined with a specific condition that compares two consecutive iterations. Since I am new to programming, it would be great if the solution is simple and easy to understand for me... :)
Although I realize this code snippet does not work as intended, the idea is clear. For example, when given "12534487" as input, I would like the output to be "12534-4-87".
ar = prompt("numberInput").split("");
ar.map(x => parseInt(x));
ar.addDashToEven();
const addDashToEven = (a, b) => {
for (a % 2 == 0 && b % 2 == 0) {
a = a + "-"
}
}