Last active
May 21, 2019 12:57
-
-
Save realinit/5e76426ec343a75765f9dd22fea68e7a to your computer and use it in GitHub Desktop.
how to check modify price entered by client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// still working on optimization for this code | |
var addFloatsToArray = function (a) { | |
var l = ([]); | |
for (var i = 0; i < a.length; i++) { | |
var f = a[i]; | |
{ | |
/* add */ (l.push(f) > 0); | |
} | |
} | |
return l; | |
}; | |
var getIncorrectCount = function () { | |
var origItems = ["rice", "sugar", "wheat", "cheese"]; | |
var origPrices = [13.45, 78.78, 19.00, 442.45]; | |
var items = ["rice", "cheese"]; | |
var prices = [15.99, 400.79]; | |
var originalItems = (origItems.slice(0).slice(0)); | |
var originalPrices =addFloatsToArray(origPrices); | |
var actualItems = (items.slice(0).slice(0)); | |
var actualPrices = addFloatsToArray(prices); | |
var count = 0; | |
for (var i = 0; i < actualItems.length; i++) { | |
var aItems = actualItems[i]; | |
{ | |
var oi = originalItems.indexOf(aItems); | |
var op = originalPrices[oi]; | |
var aii = actualItems.indexOf(aItems); | |
if (op !== actualPrices[aii]) { | |
count++; | |
} | |
} | |
} | |
console.log(count); | |
}; | |
getIncorrectCount(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Javascript:- Michael is a shop owner who keeps a list of the name and sale price for each item in the store's inventory.
At each sale, his employees record the name and sale price of each item sold. Michael suspects his
manager, Alex, of embezzling money by modifying the sale price of some of the items. Write a program
that finds the number of times Alex recorded an incorrect sale price.