-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign.js
68 lines (56 loc) · 1.19 KB
/
design.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//Global variables
var objects = [
{name: "Stefka"},
{name: "Lola"},
{name: "Dawid"},
{name: "Ewu"},
];
var nuts = [
{name: "migdały"},
{name: "nerkowce"},
{name: "laskowe"},
{name: "włoskie"},
];
var veggi = [
{name: "carrot"},
{name: "cucumber"},
{name: "khale"},
{name: "spinach"},
];
var fruits = [
{name: "apple"},
{name: "lemon"},
{name: "banana"},
{name: "kiwi"},
];
//Adds element to the end of the list
function addElement(name) {
objects.push({name: name});
return objects;
}
//Removes element from selected index placy on the list
function removeElement(index) {
objects.splice(index, 1);
return objects;
}
//Moves elements from one array positon to another
function moveElement(fromIndex, toIndex) {
var element = objects[fromIndex];
objects.splice(fromIndex, 1);
objects.splice(toIndex, 0, element);
return objects;
}
//Join lists and creates new one
function joinLists(list1, list2, list3, list4) {
var newList = list1.concat(list2, list3, list4);
return newList;
}
//Sorts list alphabetically
function sortList(list) {
list.sort(function(a, b) {
if(a.name < b.name) return -1;
if(a.name > b.name) return 1;
return 0;
});
return list;
}