-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrone-fly-by.js
More file actions
22 lines (16 loc) · 1.14 KB
/
drone-fly-by.js
File metadata and controls
22 lines (16 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// CODEWARS 7KYU DRONE FLY-BY
// INSTRUCTIONS:
// The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant.
// In this kata we will recreate that stunt... sort of.
// You will be given two strings: lamps and drone. lamps represents a row of lamps, currently off, each represented by x. When these lamps are on, they should be represented by o.
// The drone string represents the position of the drone T (any better suggestion for character??) and its flight path up until this point =. The drone always flies left to right, and always begins at the start of the row of lamps. Anywhere the drone has flown, including its current position, will result in the lamp at that position switching on.
// Return the resulting lamps string. See example tests for more clarity.
//SOLUTION:
function flyBy(lamps, drone){
let tIndex= drone.indexOf('T')
let tPath = lamps.substring(0, tIndex+1).replace(/x/g, 'o')
return tPath +lamps.substring(tPath.length,lamps.length)
}
//SOLUTION 2:
const flyBy = (lamps, drone) =>
`${`o`.repeat(drone.length)}${lamps}`.slice(0, lamps.length);