dilyana2001

Heart Delivery

Jun 6th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function heartDelivery(strArr) {
  2.     let count = 0
  3.     let path = strArr.shift().split('@').map(Number)
  4.     while (strArr[0] !== 'Love!') {
  5.         let [jump, index] = strArr[0].split(' ').map(Number)
  6.         count += index
  7.        if (count >= path.length) {
  8.             count = 0
  9.         }
  10.         let number = path[count]
  11.         if (number > 0) {
  12.             path.splice(count, 1, number -= 2)
  13.             if (number === 0) {
  14.                 console.log(`Place ${count} has Valentine's day.`)
  15.            }
  16.        } else if (number <= 0) {
  17.            console.log(`Place ${count} already had Valentine's day.`)
  18.         }
  19.         strArr.shift()
  20.     }
  21.     let failed = path.filter(x => x > 0)
  22.     if (strArr[0] === 'Love!')
  23.         console.log(`Cupid's last position was ${count%path.length}.`)
  24.    if (failed.length <= 0) {
  25.        console.log(`Mission was successful.`)
  26.    } else {
  27.        console.log(`Cupid has failed ${failed.length} places.`)
  28.    }
  29. }
Add Comment
Please, Sign In to add comment