Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. array = ['Siya', 'Drinking', 'Fucking', 'Eating'];
  2.  
  3. let map = {}
  4. function cv() {
  5. let result = ""
  6. array.forEach(element => {
  7. let v = element.length; // length of every word
  8. console.log(v)
  9.  
  10. // checks and add the last letter of the word
  11. if(map[element[v - 1]] == undefined) {
  12. map[element[v - 1]] = 1
  13. } else {
  14. let x = element[v - 1];
  15. // we get the letter as 'x' the call endWithLetter() with the original array and the repeating letter
  16. result = endWithLetter(array, x);
  17. }
  18. });
  19. return result;
  20. }
  21.  
  22.  
  23. function endWithLetter(array, letter) {
  24. var newArr = []
  25. for (let i = 0; i < array.length; i++) {
  26. const element = array[i];
  27. // loops through array and push the word that end with the given letter
  28. if(element.endsWith(letter)) {
  29. newArr.push(element);
  30. }
  31. }
  32. return newArr;
  33. }
  34.  
  35. console.log(cv())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement