import Ember from
'ember'
;
import {
without, toArray, unshiftObject, unshiftObjects,
removeAt, objectAt, find, replace, uniq
} from
'@ember/array'
;
export
default
Ember.Controller.extend({
actions: {
withoutItem(item) {
console.log(item)
let tempItems;
tempItems =
this
.partyItems.without(item);
let str =
''
;
for
(let i = 0; i < tempItems.length; i++)
str += tempItems[i] +
'\n'
;
alert(str);
this
.set(
'item'
,
''
);
},
addItems(itemString) {
this
.itemList = itemString.split(
','
).toArray();
if
(
this
.itemList.length == 1)
this
.partyItems.unshiftObject(
this
.itemList[0]);
else
this
.partyItems.unshiftObjects(
this
.itemList);
this
.set(
'itemString'
,
''
);
},
removeItems(start, end) {
this
.partyItems.removeAt(start, end);
},
getObject(idx) {
alert(`The item at index ${idx} is
${
this
.partyItems.objectAt(idx)}`);
},
findMultipleWordItems() {
let reqItem =
this
.partyItems.find((item) =>
item.split(
' '
).toArray().length > 1);
alert(reqItem);
},
replaceItem(itemString) {
this
.itemList = itemString.split(
','
).toArray();
if
(
this
.itemList.length >
this
.partyItems.length)
alert(
'Error'
);
this
.partyItems.replace(0,
this
.itemList.length,
this
.itemList);
},
getUniqueItems() {
let tempItems =
this
.partyItems.uniq();
let str =
''
;
for
(let i = 0; i < tempItems.length; i++)
str += tempItems[i] +
'\n'
;
alert(str);
this
.set(
'item'
,
''
);
},
},
});