Created
February 18, 2019 14:15
-
-
Save Gideon877/d23b3b991e5b54b5ff54eca7b1ee3588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Unalo please review