These are the questions I was asked In a frontend interview for a ReactJS position.
If you ask me to clone Netflix UI I will do It in shortest p...
For further actions, you may consider blocking this person and/or reporting abuse
people.reduce(...)
answer is a masterpiece 👏🏻Masterpiece.
A more generic solution to group by any property:
Didn't understand It can you explain a little more.
I may use the implicit variables so that you could read easily, see my comments for the explanations
Then we can use
people.groupBy('gender')
orpeople.groupBy('age')
Using .filter for the second task
people = [
// { name: 'Alice', age: 21, gender: "female" },
// { name: 'Max', age: 20, gender: "male" },
// { name: 'Jane', age: 20, gender: "female" },
// { name: 'Jon', age: 21, gender: "male" },
// { name: 'Alex', age: 20, gender: "male" }
// ]
// const male=people.filter((el)=>el.gender=="male")
// const female=people.filter((el)=>el.gender=="female")
// console.log({male:male,female:female})
// let result = [{x: 1}, {x: 2}, {x: 3}];
// res=result.reduce((acc,el)=>acc+el.x,0)
let value = "5+8=x";
let arr=value.split("=")
arr=arr[0].split("+").map(Number).reduce((acc,e)=>acc+e)
console.log(arr)