LeetCode #496 Next Greater Element I
var nextGreaterElement = function(nums1, nums2) {
let result = [];
for(let i = 0; i < nums1.length; i++) {
let greaterNumbers = [];
let numIndex = nums2.indexOf(nums1[i]);
for(let j = numIndex; j < nums2.length; j++) {
nums2[j] > nums1[i] ? greaterNumbers.push(nums2[j]) : null;
}
if(greaterNumbers.length) {
result.push(greaterNumbers[0]);
} else {
result.push(-1);
}
}
return result;
};