You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 1.4 Given an array of integers, find the largest difference between two elements such that the element of lesser value must come before the greater element
69
+
vararray=[7,8,4,9,9,15,3,1,10];
26
70
27
-
// Some and Every Checks
28
-
// Array.prototype.some() // is at least one person 19 or older?
29
-
// Array.prototype.every() // is everyone 19 or older?
71
+
functionsortArray(a,b){
72
+
returna-b;
73
+
}
74
+
varmaybe=array.filter(function(val,i,ary){
75
+
if(i>0){
76
+
if((val>ary[i-1])){
77
+
// console.log('val: ' + val);
78
+
// console.log('previous val: ' + ary[i - 1]);
79
+
// console.log((val - ary[i - 1]));
80
+
returnparseInt(val)-parseInt((ary[i-1]));
81
+
//return val
82
+
}
83
+
//console.log(val);
84
+
//console.log(val - ary[i - 1]);
85
+
//return diff(val, ary[i - 1]);
86
+
}
87
+
});
88
+
//var largest = (maybe.sort(sortArray).reverse())[0];
89
+
console.log(maybe);
90
+
//console.log(maybe.sort(sortArray).reverse());
91
+
</script>
92
+
</body>
30
93
31
-
// Array.prototype.find()
32
-
// Find is like filter, but instead returns just the one you are looking for
0 commit comments