-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hipsterificacion.js
34 lines (26 loc) · 974 Bytes
/
Hipsterificacion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Escriba una función hipsterfy(sentence)que tome una cadena de oraciones y
devuelva la oración en la que a cada palabra le falta la última vocal.
*/
let removeLastVowel = function(word) {
let vowels = 'aeiou';
for(let i = word.length - 1; i >= 0; i--) {
let char = word[i];
if (vowels.includes(char)) {
return word.slice(0, i) + word.slice(i + 1);
}
}
return word;
};
let hipsterfy = function(sentence) {
let newWords = [];
let words = sentence.split(' ');
for (let i = 0; i < words.length; i++) {
let word = words[i];
newWords.push(removeLastVowel(word));
}
return newWords.join(' ');
};
console.log(hipsterfy('When should everyone wake up?')); // 'Whn shold everyon wak p?'
console.log(hipsterfy('get ready for our bootcamp')); // 'gt redy fr or bootcmp'
console.log(hipsterfy('panthers are great animals')); // 'panthrs ar gret animls'