Skip to content

Instantly share code, notes, and snippets.

@realinit
Last active May 21, 2019 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realinit/5e76426ec343a75765f9dd22fea68e7a to your computer and use it in GitHub Desktop.
Save realinit/5e76426ec343a75765f9dd22fea68e7a to your computer and use it in GitHub Desktop.
how to check modify price entered by client
// 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();
@realinit
Copy link
Author

realinit commented May 17, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment