group by property javascript use reduce

reduce,es6,tipjs

Group by property javascript use reduce

const result = [
  {subject: 'blog javascript', marks: 41},
  {subject: 'anonystick.com', marks: 59},
  {subject: 'blog developers', marks: 36},
  {subject: 'blog programmers', marks: 90},
  {subject: 'medium.com', marks: 64},
];
let initialValue = {
  pass: [], 
  fail: []
}
const groupedResult = result.reduce((accumulator, current) => {
  (current.marks >= 50) ? accumulator.pass.push(current) : accumulator.fail.push(current);
  return accumulator;
}, initialValue);
console.log(groupedResult);

Có thể bạn đã miss một số snippets code

encode/decode base64 with JS

Encoding to base64 is done with the btoa command

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Đếm có bao nhiêu items giống nhau trong một array

reduce javascript. Đếm có bao nhiêu items giống nhau trong một array

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

Random String

Random String với độ dài tuỳ chọn