Small JavaScript answer - trying to think how I would do this with a reduce for fun:
const digits = num => { const result = []; const parts = String(num).split('').map(n => n | 0); for(let i = 0; i < parts.length; i++) { for (let j = i + 1; j < parts.length; j++) { result.push(parts[i] + parts[j]); } } return result; };
something like this maybe
const prepareArray = nr => String(nr).split('').map(Number); const printPairs = arr => arr.reduce((acc, val, index) => { for(let i = index+1; i < arr.length; i++){ acc.push(val+arr[i]); } return acc; }, []); console.log(printPairs(prepareArray(12345)))
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.
Small JavaScript answer - trying to think how I would do this with a reduce for fun:
something like this maybe