Closed romebell closed 3 years ago
function evenCaps(sentence) {
let string = sentence.split('');
for(let i = 0; i < string.length; i++) {
if (i % 2 === 0) {
string[i] = string[i].toUpperCase();
}
}
return string.join('');
}
console.log(evenCaps("Tom got a small piece of pie"));
function evenCaps (sentence) {
let sentenceArray = [];
sentenceArray = sentence.split('');
let newArray = [];
for (let i = 0; i < sentenceArray.length; i++) {
if (i % 2 === 0) {
newArray.push(sentenceArray[i].toUpperCase());
} else {
newArray.push(sentenceArray[i])
}
}
let newSentence = newArray.join('');
return newSentence
}
const evenCaps = (sentence) =>{ newStr = '' for (let i = 0; i < sentence.length; i++){ if (i%2 === 0) newStr += sentence[i].toUpperCase() else newStr += sentence[i] } console.log(newStr) } evenCaps('this is my sentence')
function evenCaps (sentence) {
let sentenceArray = [];
sentenceArray = sentence.split('');
let newArray = [];
for (let i = 0; i < sentenceArray.length; i++) {
if (i % 2 === 0) {
newArray.push(sentenceArray[i].toUpperCase());
} else {
newArray.push(sentenceArray[i])
}
}
let newSentence = newArray.join('');
return newSentence
}
Challenge 1
Write a function
mindPsAndQs(str)
that accepts a string of uppercase letters. The function should return the length of the longest consecutive streak of the letters 'P' and 'Q'.Hint: Use two variables. One to track the length of the current streak and another to track the length of the longest streak so far. Think of using a strategy similar to maxValue. This can also be solved using a single loop!
Nested loops not needed!
Examples: