/*
input:
[
['usd', 'buy', 10000],
['usd', 'sell', 5000],
['gbd', 'buy', 9000],
['eur', 'sell', 7000],
['uah', 'buy', 10000],
['usd', 'sell', 25000],
]
*/
/*
output:
{
usd: [10000, 30000],
gbd: [9000, 0],
eur: [0, 7000],
uah: [10000, 0],
}
*/
const input = [
['usd', 'buy', 10000],
['usd', 'sell', 5000],
['gbd', 'buy', 9000],
['eur', 'sell', 7000],
['uah', 'buy', 10000],
['usd', 'sell', 25000],
]
/*
output:
{
usd: [10000, 30000],
gbd: [9000, 0],
eur: [0, 7000],
uah: [10000, 0],
}
*/
function solution(input) {
return input.reduce((accumulator, currentValue) => {
let [currency, type, amount] = currentValue;
if (!accumulator[currency]) {
accumulator[currency] = [0, 0];
}
// accumulator[currency][type === 'buy' ? 0 : 1] += amount;
if (accumulator[currency] && type === 'buy') {
accumulator[currency][0] += amount;
} else {
accumulator[currency][1] += amount;
}
return accumulator;
}, {});
}
console.log(solution(input));
List<DataObj> output = new ArrayList<>();
dataObjs2.stream().reduce(dataObjs2.get(0), (accumulator, currentValue) -> {
/*
const isMatches = a2.some((element) => {
return element.id === currentValue.id;
});
if (!isMatches) {
accumulator.push(currentValue);
}
*/
List<DataObj> matchesList = dataObjs1.stream().filter((element) -> {
return element.getId().equals(currentValue.getId());
}).collect(Collectors.toList());
if (matchesList.isEmpty()) {
output.add(currentValue);
}
return accumulator;
});
package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
class DataObj {
private String id;
private String title;
public DataObj(String id, String title) {
this.id = id;
this.title = title;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return "DataObj{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
'}';
}
}
public class Test {
public static void main(String[] args) {
List<DataObj> dataObjs1 = new ArrayList<>();
List<DataObj> dataObjs2 = new ArrayList<>();
DataObj dataObj1 = new DataObj("1", "one");
DataObj dataObj2 = new DataObj("2", "two");
DataObj dataObj3 = new DataObj("3", "three");
DataObj dataObj10 = new DataObj("10", "ten");
dataObjs1.add(dataObj1);
dataObjs1.add(dataObj10);
dataObjs2.add(dataObj1);
dataObjs2.add(dataObj2);
dataObjs2.add(dataObj3);
dataObjs2.add(dataObj10);
System.out.println("dataObjs2 " + dataObjs2);
List<DataObj> output = new ArrayList<>();
dataObjs2.stream().reduce(dataObjs2.get(0), (accumulator, currentValue) -> {
/*
const isMatches = a2.some((element) => {
return element.id === currentValue.id;
});
if (!isMatches) {
accumulator.push(currentValue);
}
*/
List<DataObj> matchesList = dataObjs1.stream().filter((element) -> {
return element.getId().equals(currentValue.getId());
}).collect(Collectors.toList());
if (matchesList.isEmpty()) {
output.add(currentValue);
}
return accumulator;
});
System.out.println("output " + output);
}
}
[Order{date='2017-10-16 12:07:07', docTypesName='Приход', docId=564564867361367, image='https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg', name='Молочный Изюм 100', price=102.0, quantity=45, removed=0}, Order{date='2017-10-16 12:07:07', docTypesName='Приход', docId=564564867361367, image='https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg', name='Русская картошка чедар 50', price=46.3, quantity=45, removed=0}, Order{date='2017-10-16 12:07:07', docTypesName='Расход', docId=564564867361367, image='https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg', name='Русская картошка чедар 50', price=46.3, quantity=45, removed=0}, Order{date='2017-11-29 17:26:57', docTypesName='Расход', docId=564564867361365, image='https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg', name='Молочный Изюм 100', price=102.0, quantity=6, removed=0}]
SELECT
docs.date,
docTypes.name,
rows.docId,
products.image,
products.name,
products.price,
rows.quantity,
products.removed
FROM docs
INNER JOIN docTypes, rows, products ON docs.id = rows.docId
WHERE NOT docs.removed AND NOT docTypes.removed
ORDER BY docs.date;
window.addEventListener('scroll', function (e) {
console.log(window.pageXOffset);
});
const sliderRef = document.querySelector(".slider");
const x = sliderRef.scrollWidth - sliderRef.getBoundingClientRect().width + sliderRef.getBoundingClientRect().x;
window.addEventListener('scroll', function (e) {
console.log(window.pageXOffset);
});
.animation {
transform: translateX(-3161px);
}