JSFiddle - React, Tailwind, and code Playground
JavaScript
const T = [5, -2, 3, 8, 6];
const S = [-5, -5, -5, -42, 6, 12];
console.log(solution(T));
function solution(T) {
let position = 0;
let winterHighestTemp = T[0];
let maximumYearTemp = T[0];
T.forEach((item, index) => {
if(item < winterHighestTemp) {
position = index + 1;
} else if(maximumYearTemp > item) {
winterHighestTemp = item;
}
});
return position;
}