Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array = ['Siya', 'Drinking', 'Fucking', 'Eating'];
- let map = {}
- function cv() {
- let result = ""
- array.forEach(element => {
- let v = element.length; // length of every word
- console.log(v)
- // checks and add the last letter of the word
- if(map[element[v - 1]] == undefined) {
- map[element[v - 1]] = 1
- } else {
- let x = element[v - 1];
- // we get the letter as 'x' the call endWithLetter() with the original array and the repeating letter
- result = endWithLetter(array, x);
- }
- });
- return result;
- }
- function endWithLetter(array, letter) {
- var newArr = []
- for (let i = 0; i < array.length; i++) {
- const element = array[i];
- // loops through array and push the word that end with the given letter
- if(element.endsWith(letter)) {
- newArr.push(element);
- }
- }
- return newArr;
- }
- console.log(cv())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement