My take on this challenge with JS
const neighbors = number => { const format = n => { n = `${n}`.padStart(10, '0'); return `${`${n}`.substr(0,3)}-${`${n}`.substr(3, 3)}-${`${n}`.substr(6, 4)}`; }; const nArray = [...number].reduce((t, d, i) => { const n1 = Number(number) + Math.pow(10, i); const n2 = number - Math.pow(10, i); t.push(format(n1)); t.push(format(n2)); return t; }, []) return nArray; } /** neighbors("5555555555"); [ "555-555-5556", "555-555-5554", "555-555-5565", "555-555-5545", "555-555-5655", "555-555-5455", "555-555-6555", "555-555-4555", "555-556-5555", "555-554-5555", "555-565-5555", "555-545-5555", "555-655-5555", "555-455-5555", "556-555-5555", "554-555-5555", "565-555-5555", "545-555-5555", "655-555-5555", "455-555-5555" ] **/
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My take on this challenge with JS