Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const test = "ABCCABC";
- let countSubstrings = ((input, length) => {
- let countMap = new Map();
- for(let i = 0; i < input.length - (length - 1); i++){
- const window = input.slice(i, i + length);
- if(countMap.has(window)){
- countMap.set(window, countMap.get(window) + 1);
- }
- else{
- countMap.set(window, 1);
- }
- }
- for([key, count] of countMap){
- console.log(key + ": " + count);
- }
- });
- for(let i = 1; i <= test.length; i ++){
- countSubstrings(test, i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement