Сервер предоставляет ответ в фоматах xml или json, в зависимости от значения заголовка “Accept” клиента. Возможные значения:
application/xml
application/json
В чем нам даст профит то, что у нас отсортированный набор данных, если мы начнем поиск начиная с id = 1
var cashes = [
['PENNY', 1],
['NICKEL', 5],
['DIME', 10],
['QUARTER', 25],
['ONE', 100],
['FIVE', 500],
['TEN', 1000],
['TWENTY', 2000],
['ONE HUNDRED', 10000]
];
function checkCashRegister(price, cash, cid) {
var change = [];
var changeAmount = Math.round(cash * 100) - Math.round(price * 100);
var closed = true;
for (var position = cid.length - 1; position >= 0; position--) {
var changePosition = Math.floor(changeAmount / cashes[position][1]) * cashes[position][1];
var cidPosition = Math.round(cid[position][1] * 100);
if (changePosition > cidPosition) {
changePosition = cidPosition;
}
if (changePosition > 0) {
change.push([cid[position][0], changePosition / 100]);
}
changeAmount -= changePosition;
closed &= (changePosition == cidPosition);
}
if (changeAmount > 0) {
return {status: 'INSUFFICIENT_FUNDS', change: []};
}
if (closed) {
return {status: 'CLOSED', change: cid};
}
return {status: 'OPEN', change: change};
}
The 406 (Not Acceptable) status code indicates that the target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request (Section 5.3), and the server is unwilling to supply a default representation.
The server SHOULD generate a payload containing a list of available representation characteristics and corresponding resource identifiers from which the user or user agent can choose the one most appropriate. A user agent MAY automatically select the most appropriate choice from that list. However, this specification does not define any standard for such automatic selection, as described in Section 6.4.1.