There is a file that represents the accounting program database. My task is to calculate the sum of all orders. But here is the problem, the database has duplicate lines, because of this, the amount goes an order of magnitude higher.
Task: check order time and order number, if it is the same - ignore.
But I just can't figure out how to do it ...
Here, in fact, what is at the moment:
var xhr = new XMLHttpRequest(); var arr = []; var newArr = []; var dNewArr = []; var sum = 0; var dSum = 0; xhr.open('GET', 'input.mfl', false); xhr.send(); if (xhr.status !== 200) { alert(xhr.status + ': ' + xhr.statusText); } var file = xhr.responseText; var file = file.split('\n'); for (i = 0; i < file.length; i++) { arr = file[i].split('#') newArr.push(arr[4]) sum += parseFloat(newArr[i]); dNewArr.push(arr[6]) dSum += parseFloat(dNewArr[i]); } document.write('Без скидки: ' + sum + '<br>'); document.write('Со скидкой: ' + dSum + '<br>'); document.write('Скидка: ' + (sum - dSum)); Example input.mfl:
742#?#Слава-Кассир#Слава-Кассир#15#0#15#2016@11@30@19@6@28#2016@11@30@19@6@28#False$Чернігівське світле розл. мал.#1 337#?#Слава-Кассир#Администратор#11132#20#8905.6#2016@11@30@16@1@58#2016@11@30@16@1@58#False$Салат из печени трески с гренками#4$Оливье с креветками и перепелиными яйцами#6$Сельдь под шубой#3$Мясная тарелка.#3$Рыбная тарелка.#3$Рыба фаршированная.#30$Холодец по-царски.#20$Блины с сёмгой и кремом из сыра "Буко"#5$Торт печёночный#3$Тарелка домашних солений.#3$Закуска из огурцов с укропом и чесноком.#3$Рулетики из баклажанов с мясом в томатном соусе.#3$Шампиньоны фаршированные моцареллой.#3$Свиные тефтели с черносливом.#3$Утка. запечённая с яблоками в медово-апельсиновой глазури.#42$Голубцы по-домашнему.#5$Хлеб#30$Каберне совіньйон червоне сухе#30$Одесса н/сол.#1$Козацька рада(Банкет)#20$Узвар#15$Картофель. запечённый ломтиками.#6 999#?#Слава-Кассир#Корбут О.#150#0#150#2016@11@30@18@9@55#2016@11@30@18@9@55#False$Американо#1$Молоко до кави#1$Чернігівське Біле розл. вел.#2$Чернігівське Біле розл. вел.#1$Чернігівське Біле розл. вел.#2 Work can be viewed here: https://dream-studio.org.ua/project/
var file = file.split('\n');and loop through all these arrays, select and summarize the values. I can not understand how to exclude the same arrays. I understand that this should be before the cycle ... - ProstoJohninput.mflfile so that it is clear what you load and how you parse - Grundy