Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function heartDelivery(strArr) {
- let count = 0
- let path = strArr.shift().split('@').map(Number)
- while (strArr[0] !== 'Love!') {
- let [jump, index] = strArr[0].split(' ').map(Number)
- count += index
- if (count >= path.length) {
- count = 0
- }
- let number = path[count]
- if (number > 0) {
- path.splice(count, 1, number -= 2)
- if (number === 0) {
- console.log(`Place ${count} has Valentine's day.`)
- }
- } else if (number <= 0) {
- console.log(`Place ${count} already had Valentine's day.`)
- }
- strArr.shift()
- }
- let failed = path.filter(x => x > 0)
- if (strArr[0] === 'Love!')
- console.log(`Cupid's last position was ${count%path.length}.`)
- if (failed.length <= 0) {
- console.log(`Mission was successful.`)
- } else {
- console.log(`Cupid has failed ${failed.length} places.`)
- }
- }
Add Comment
Please, Sign In to add comment