Skip to content

Instantly share code, notes, and snippets.

@Gideon877
Created February 18, 2019 14:15
Show Gist options
  • Save Gideon877/d23b3b991e5b54b5ff54eca7b1ee3588 to your computer and use it in GitHub Desktop.
Save Gideon877/d23b3b991e5b54b5ff54eca7b1ee3588 to your computer and use it in GitHub Desktop.
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())
@Gideon877
Copy link
Author

@Unalo please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment