You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
784 B
32 lines
784 B
function copy(from, to) {
|
|
for (var attr in to) {
|
|
if (from.hasOwnProperty(attr)) {
|
|
if (!(from[attr] instanceof Array)) {
|
|
to[attr] = from[attr];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function updateByNumber(list, from) {
|
|
var result = false;
|
|
var to = Enumerable.from(list).where(function (o) { return o.number === from.number; }).firstOrDefault();
|
|
if (to) {
|
|
copy(from, to);
|
|
}
|
|
else {
|
|
list.push(from);
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
function deleteByNumber(list, item) {
|
|
var result = false;
|
|
for (var i = 0; i < list.length; i++) {
|
|
if (list[i].number == item.number) {
|
|
list.splice(i, 1);
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
} |