Created
December 22, 2017 08:56
-
-
Save northamerican/e0abc3498e43720d2c4038e418b600fb to your computer and use it in GitHub Desktop.
challenge 341: repeating numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* https://www.reddit.com/r/dailyprogrammer/comments/7eh6k8/20171121_challenge_341_easy_repeating_numbers/ */ | |
const input = '124489903108444899' | |
const numbers = {} | |
for(let digits = 2; digits < input.length; digits++) { | |
for(let index = 0; index < input.length - digits + 1; index++) { | |
let chunk = input.substr(index, digits) | |
chunk in numbers ? | |
numbers[chunk]++ : | |
numbers[chunk] = 1 | |
} | |
} | |
Object.entries(numbers) | |
.filter(numberPair => numberPair[1] > 1) | |
.map(numberPair => numberPair.join(':')) | |
.join(' ') || 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment