Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. const getGets = (arr) => {
  2. let index = 0;
  3.  
  4. return () => {
  5. const toReturn = arr[index];
  6. index += 1;
  7. return toReturn;
  8. };
  9. };
  10. // this is the test
  11. const test = [
  12. 'anagram',
  13. '6',
  14. 'gramana',
  15. 'aaagrnm',
  16. 'anagra',
  17. 'margana',
  18. 'abc',
  19. 'xy'
  20. ]3
  21.  
  22. const gets = this.gets || getGets(test);
  23. const print = this.print || console.log;
  24.  
  25. let W = gets().split('')
  26. let NumberOfWords = gets()
  27. let matchedArr = []
  28.  
  29. console.log(W)
  30. console.log(NumberOfWords)
  31.  
  32. let checkAnagram = function(W, WORDS){
  33. if(WORDS.length !== W.length){
  34. console.log('No')
  35. }
  36. for(let i = 0; i < W.length; i++){
  37. for(let j = 0; j < WORDS.length; j++){
  38.  
  39. if(W[i] === WORDS[j]){
  40. matchedArr.push(WORDS[j])
  41.  
  42. }else if (W[i] !== WORDS[j]){
  43. matchedArr.length = 0
  44. }
  45. }
  46. }
  47. }
  48.  
  49. for(let i = 0; i < NumberOfWords; i++){
  50. let WORDS = gets().split('')
  51. let result = checkAnagram(W, WORDS)
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement