• API
• FAQ
• Tools
• Archive
daily pastebin goal
14%
SHARE
TWEET

# Untitled

a guest Aug 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function rockClimbing(holds, friends) {
2.
3.     var highestHold = 0
4.     var result = 0
5.     var friendMatch = Math.max(...friends)
6.     friends.sort(function(a, b){return b-a})
7.
8.     // find the biggest diff between holds
9.     for (var i = holds.length-1; i>0; i--) {
10.         if (distance = holds[i] - holds[i-1] > highestHold) {
11.             highestHold = holds[i] - holds[i-1]
12.         }
13.     }
14.
15.     // check if all can climb
16.     for (var i = 0; i < friends.length; i++) {
17.         console.log(friends)
18.         console.log("i before is " + i)
19.         console.log(Math.max(...friends))
20.         let currentFriend = i
21.         friendMatch = Math.max(...friends)
22.
23.         // iterate over to find a match
24.         for (var j = 0; j < friends.length; j++) {
25.            // if (!friends[currentFriend])
26.             if ((friendMatch > friends[currentFriend] + friends[j]) && (friends[j] !== friends[currentFriend])) {
27.                 if (friendMatch >= highestHold) {
28.                     friendMatch = friends[currentFriend] + friends[j]
29.                     var currentPairedFriend = friends[j]
30.                     var currentPairedFriend = j
31.                     console.log(currentPairedFriend)
32.                     i = j-1
33.                     }
34.                 }
35.         }
36.         delete friends[currentFriend]
37.         //friends.splice(i, 1);
38.         console.log("i after is " + i)
39.
40.
41.         // if (friends[i] >= highestHold) {
42.         //     result++
43.         // }
44.     }
45.
46.
47.     // sort and match lowest with highest?
48.
49.     // find the best match for climb - lowest number allowing to go to the top
50.
51.     // that best match 2nd dude needs to be able to climb as well
52.     // Math.max.apply(Math, data);
53.
54.
55.     for (var i=0; i<holds.length; i++) {
56.         if(holds[i]){
57.             result++}
58.     }
59.
60.     return result
61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top