JSFiddle - React, Tailwind, and code Playground

Making a lock opener. One spin at a time - can change 1 number either up or down. The numbers (from 0 to 9) overflow (9 -> 0, 0 -> 9).

by Yurii Predborskyi

JavaScript

let combo = '1234';
let arr = [];
for (let j = 0; j < combo.length; j++) {
  let up = combo.split(''), dn = up.slice();
  up[j] = (Number.parseInt(up[j]) + 1) % 10;
  dn[j] = (Number.parseInt(dn[j]) + 9) % 10;
	/*
  if (dn[j] < 0) {
    dn[j] = 10 + dn[j];
  }
  */
  arr.push(up.join(''));
  arr.push(dn.join(''));
  // if (dn[j] < 0)
}

console.log('up', arr[0])
console.log('dn', arr[1])
console.log('arr', arr);