“JS Array berkurang” Kode Jawaban

jumlah array javascript

const sum = arr => arr.reduce((a, b) => a + b, 0);
Batman

Kurangi JavaScript

let array = [36, 25, 6, 15];
 
array.reduce((acc, curr) => acc + curr, 0)
// 36 + 25 + 6 + 15 = 82
Rick Oburu

JavaScript berkurang

var array = [36, 25, 6, 15];

array.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0); // 36 + 25 + 6 + 15 = 82
TC5550

.reduce javascript

reduce function sample solution
Tuffour Boateng

Kurangi dalam JavaScript

// Reduce in javascript advance
// output: { '22': 2, '24': 2, '26': 1 }
const user = [
  {name:"Abhishek",age:24},
  {name:"Dhruval",age:22},
  {name:"Anish",age:26},
  {name:"Aakash",age:22},
  {name:"Darshil",age:24},
]
const newUser = user.reduce((acc,cur)=>{
  if(acc[cur.age]){
    acc[cur.age] = acc[cur.age] +1 
  }
  else{
    acc[cur.age] = 1 
  }
  return acc;
},{})

console.log(newUser)
Abhishek

JS Array berkurang

// Arrow function
reduce((previousValue, currentValue) => { /* ... */ } )
reduce((previousValue, currentValue, currentIndex) => { /* ... */ } )
reduce((previousValue, currentValue, currentIndex, array) => { /* ... */ } )
reduce((previousValue, currentValue, currentIndex, array) => { /* ... */ }, initialValue)

// Callback function
reduce(callbackFn)
reduce(callbackFn, initialValue)

// Inline callback function
reduce(function(previousValue, currentValue) { /* ... */ })
reduce(function(previousValue, currentValue, currentIndex) { /* ... */ })
reduce(function(previousValue, currentValue, currentIndex, array) { /* ... */ })
reduce(function(previousValue, currentValue, currentIndex, array) { /* ... */ }, initialValue)
Tung

Jawaban yang mirip dengan “JS Array berkurang”

Pertanyaan yang mirip dengan “JS Array berkurang”

Lebih banyak jawaban terkait untuk “JS Array berkurang” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya