Skip to content

Instantly share code, notes, and snippets.

@Maryna2019
Last active November 28, 2019 16:44
Show Gist options
  • Save Maryna2019/110da7f5ddd06fcfd083de01448906fa to your computer and use it in GitHub Desktop.
Save Maryna2019/110da7f5ddd06fcfd083de01448906fa to your computer and use it in GitHub Desktop.
solution kickstart
let allSMS = "SMS messages are really short",
maxLength = 12;
function solution(allSMS,maxLengthSMS) {
let words = allSMS.split(" "),
amountSMS = 1,
currentSMS = " ";
for (let i = 0; i < words.length; i++) {
if (words[i].length > maxLengthSMS){
return -1;
} if (currentSMS === " ") {
currentSMS = words[i];
} else {
currentSMS = currentSMS + " " + words[i];
} if (currentSMS.length >= maxLengthSMS) {
currentSMS = " ";
amountSMS ++;
}
}
return amountSMS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment