Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rockClimbing(holds, friends) {
- var highestHold = 0
- var result = 0
- var friendMatch = Math.max(...friends)
- friends.sort(function(a, b){return b-a})
- // find the biggest diff between holds
- for (var i = holds.length-1; i>0; i--) {
- if (distance = holds[i] - holds[i-1] > highestHold) {
- highestHold = holds[i] - holds[i-1]
- }
- }
- // check if all can climb
- for (var i = 0; i < friends.length; i++) {
- console.log(friends)
- console.log("i before is " + i)
- console.log(Math.max(...friends))
- let currentFriend = i
- friendMatch = Math.max(...friends)
- // iterate over to find a match
- for (var j = 0; j < friends.length; j++) {
- // if (!friends[currentFriend])
- if ((friendMatch > friends[currentFriend] + friends[j]) && (friends[j] !== friends[currentFriend])) {
- if (friendMatch >= highestHold) {
- friendMatch = friends[currentFriend] + friends[j]
- var currentPairedFriend = friends[j]
- var currentPairedFriend = j
- console.log(currentPairedFriend)
- i = j-1
- }
- }
- }
- delete friends[currentFriend]
- //friends.splice(i, 1);
- console.log("i after is " + i)
- // if (friends[i] >= highestHold) {
- // result++
- // }
- }
- // sort and match lowest with highest?
- // find the best match for climb - lowest number allowing to go to the top
- // that best match 2nd dude needs to be able to climb as well
- // Math.max.apply(Math, data);
- for (var i=0; i<holds.length; i++) {
- if(holds[i]){
- result++}
- }
- return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement