Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const test = "ABCCABC";
  2.  
  3. let countSubstrings = ((input, length) => {
  4.   let countMap = new Map();
  5.   for(let i = 0; i < input.length - (length - 1); i++){
  6.     const window = input.slice(i, i + length);
  7.     if(countMap.has(window)){
  8.       countMap.set(window, countMap.get(window) + 1);
  9.     }
  10.     else{
  11.       countMap.set(window, 1);
  12.     }
  13.   }
  14.   for([key, count] of countMap){
  15.     console.log(key + ": " + count);
  16.   }
  17. });
  18.  
  19. for(let i = 1; i <= test.length; i ++){
  20.   countSubstrings(test, i);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement