Александр3297,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script>
var phoneBook = {};
var methods = {};
methods.add = function(name, arr) {
if (!this.hasOwnProperty(name)) {
this[name] = {"numbr":[]};
}
var numbr = this[name].numbr;
arr = arr.trim().split(/,/);
arr.forEach(function(tel) {
if (numbr.indexOf(tel) == -1) {
numbr.push(tel);
}
});
return this;
};
methods.remove_phone = function(arr) {
var that = this;
arr = arr.trim().split(/,/);
Object.keys(that).forEach(function(name) {
var numbr = that[name].numbr;
arr.forEach(function(tel) {
var indx = numbr.indexOf(tel);
if (indx !== -1) {
numbr.splice(indx, 1);
}
});
if (!numbr.length) {
delete that[name];
}
});
return this;
};
methods.show = function() {
document.body.insertAdjacentHTML("beforeEnd", "<div>" + JSON.stringify(this) + "</div>");
return this
}
function fn(command) {
command = command.trim().split(/\s+/);
var method = command[0].toLowerCase();
if (methods[method]) {
methods[method].apply(phoneBook, command.slice(1));
}
};
var command = "ADD Ivan 555-10-01,555-10-03";
fn(command);
fn("SHOW");
command = "ADD Ivan 555-10-02";
fn(command);
fn("SHOW");
command = "REMOVE_PHONE 555-10-03";
fn(command);
fn("SHOW");
command = "ADD Alex 555-20-01";
fn(command);
fn("SHOW");
command = "REMOVE_PHONE 555-20-01";
fn(command);
fn("SHOW");
</script>
</body>
</html>