let a = [
{
"code":"CL",
"tnved10":"7318158100",
"2019":"33",
"2020":"0.00",
"2021":"0.00"
},
{
"code":"CN",
"tnved10":"7318158100",
"2019":"7540001.66",
"2020":"8164813.34",
"2021":"20980774.64"
}]
let b = a.reduce((acc, current) => {
[2019, 2020, 2021].forEach(i => acc[i] += Number(current[i]))
return acc
}, {'2019': 0, '2020': 0, '2021': 0});
console.log(b)
const years = [2019, 2020, 2021]
let b = a.reduce((acc, current) => {
years.forEach(i => acc[i] += Number(current[i]))
return acc
}, {'2019': 0, '2020': 0, '2021': 0});
AppServiceProvider
public function boot(){
Validator::extend('count_books', function($attribute, $value, $parameters) {
$count = IssueBook::where('client_id', $value)->where('is_returned', false)->count()
return $count < 2;
});
}
StoreRequest
public function rules()
{
return [
'category_id' => 'exists:App\Category,id',
'client_id' => 'exists:App\Client,id|count_books',
'book_id' => 'exists:App\Book,id',
'days_issued' => 'nullable|string',
'is_returned' => 'nullable|boolean',
'return_date' => 'nullable|date',
];
}
const has3 = arr => {
for (let i = 2; i < arr.length; i++) {
if (arr[i] === arr[i - 1] && arr[i] === arr[i - 2]) {
return true;
}
}
return false;
}
has3([1,2,3,3,4,5,5,5,6]) // true
has3([1,2,3,3,4,5,5,6,6]) // false
select d.DEPARTMENT_ID, d.DEPARTMENT_NAME, COUNT(e.EMPLOYEE_ID)
from departments d
left join employees e on d.DEPARTMENT_ID = e.DEPARTMENT_ID
group by d.DEPARTMENT_ID, d.DEPARTMENT_NAME;
select
departments.id,
departments.department,
count(*) as count
from departments
join employees on employees.department_id = departments.id
group by departments.id, departments.name;
select
departments.id,
departments.department,
count(*) as count
from departments
left join employees on employees.department_id = departments.id
group by departments.id, departments.name;