I have two lists and I and need to return only the first number of the tuples in odd position in which sum of the tuples is greater than 70. Example Tuples: [[2,70],[3,71],[4,72],[5,73]] return [[3],[5]]
I seem to be correct in the evaluation of the first part (sum the tuple, greater than 70 and get the odd position) but cant make it return the first element of it. Can you guys help me?
const range = (from, to) => {
let arr = [];
for (let i = from; i <= to; i++){
arr.push(i);
}
return arr
}
const ternary = fn => (a, b) => fn(a, b) ? a : b
const not = (fn) => (...args) => !fn(...args)
const greaterThan = num1 => num2 => num1 > num2 ? true : false
const longestList = (arr1, arr2) => arr1.length>arr2.length ? arr1 : arr2
const tupla = (a,b) => [a,b]
const esImpar = num => num % 2 !== 0
const zipped = (list1, list2) => {
return ternary(not(longestList))(range(1,50),range(51,80))
.map((element, index)=>{
return tupla(list1[index],list2[index])
/* return element */
})
}
//tuples in odd position that
const newArray = zipped(range(1,50),range(51,80))
.map((element, index)=>{
return element[0] + element[1] // return sum of the elements of the array
})
.filter(not(greaterThan(70))) // filters greater than 70
.filter((element, index)=>{ // filters odd elements
return esImpar(index)
})
console.log(newArray)