Last active
November 28, 2019 16:44
-
-
Save Maryna2019/110da7f5ddd06fcfd083de01448906fa to your computer and use it in GitHub Desktop.
solution kickstart
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
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