From 2948310f03f05ac927764c8dd08039fccfbfa8bc Mon Sep 17 00:00:00 2001 From: ghianlughi Date: Fri, 22 Dec 2023 14:52:41 +0700 Subject: [PATCH 1/4] feat: add array-methods --- array-methods/index.js | 28 +++++++++++++++++ array-methods/study-case.js | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 array-methods/index.js create mode 100644 array-methods/study-case.js diff --git a/array-methods/index.js b/array-methods/index.js new file mode 100644 index 0000000..8d9f7dc --- /dev/null +++ b/array-methods/index.js @@ -0,0 +1,28 @@ +const fruits = ['Orange','Apel','watermelom','manggo']; + +fruits.push('strawberry'); + +// console.log(fruits.toString()) + + +const person = ['Budi','joni','wahyudi']; + +person.push('wiliam','Erik','Thomas'); + +// console.log(person.toString()) + +//array foreach +person.forEach(function(data){ + console.log(data) +}) + + +// daily Assigment | tugas harian + +// buat 4 array yang keudian akan di tambahkan data dengan method push() +// setelah data array di tambahkan , kalurakan data dan tampilkan dengan forEach() +// 5 array dengan nama myHobbies, myFriends,myFavouriteFoods, My,Language +// file study-case.js + + + diff --git a/array-methods/study-case.js b/array-methods/study-case.js new file mode 100644 index 0000000..152be3f --- /dev/null +++ b/array-methods/study-case.js @@ -0,0 +1,61 @@ +// Daily Assigment + +// 1. Array myHobbies + +const myHobbies = ['runing', 'Basketball', 'swimingpoll']; + +myHobbies.push('cook','Watch movies'); + +console.log(myHobbies.toString()); + +myHobbies.forEach(function (data) { + console.log(data) +}) + +// 2. Array MyFiriends +const myFriends = ['Nanta', 'Dandi', 'Ghian']; + +myHobbies.push('Abi','Renata','ramzi'); + +console.log(myFriends.toString()); + +myFriends.forEach(function (data) { + console.log(data) +}) + +// 3. Array My FavoriteFoods +const myFavouriteFoods = ['fried rice', 'Dandifried duck', 'Geprek chicken']; + +myHobbies.push('soto','meatball'); + +console.log(myFavouriteFoods.toString()); + +myFavouriteFoods.forEach(function (data) { + console.log(data) +}) + +// 4. Array My Language +const myLanguage = ['Indonesia', 'Inggris']; + +myHobbies.push('Arabic','Italy'); + +console.log(myLanguage.toString()); + +myLanguage.forEach(function (data) { + console.log(data) +}) + +// 5. myGame +const myGame= ['PUBG', 'Mobile Legends']; + +myGame.push('Class of clans'); + +console.log(myGame.toString()); + +myGame.forEach(function (data) { + console.log(data) +}) + + + + From 76e759ea03ba778b0a7c33b618a67ec67c46a1af Mon Sep 17 00:00:00 2001 From: ghianlughi Date: Wed, 27 Dec 2023 09:57:15 +0700 Subject: [PATCH 2/4] feat: add splice method --- shift/shift.js | 4 ++++ splice/splice.js | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 shift/shift.js create mode 100644 splice/splice.js diff --git a/shift/shift.js b/shift/shift.js new file mode 100644 index 0000000..982e0fd --- /dev/null +++ b/shift/shift.js @@ -0,0 +1,4 @@ +let myHobby = ['game','Fishing',"Read Book"]; + +myHobby.shift(); +console.log(myHobby); \ No newline at end of file diff --git a/splice/splice.js b/splice/splice.js new file mode 100644 index 0000000..81b1f9e --- /dev/null +++ b/splice/splice.js @@ -0,0 +1,5 @@ +let animal = ['Kucing','Sapi','Kambing']; + +animal.splice(2,1); +animal.splice(0,0,"ikan pitek"); +console.log(animal); From f4b9db11b89c140bb10a8c0a99f564b3f22374af Mon Sep 17 00:00:00 2001 From: ghianlughi Date: Wed, 27 Dec 2023 10:47:45 +0700 Subject: [PATCH 3/4] feat: add splice and shift --- pop/pop.js | 4 ++++ pop/study-case.js | 6 ++++++ shift/study-case.js | 7 +++++++ splice/study-case.js | 9 +++++++++ unShift/study-case.js | 7 +++++++ unShift/unShift.js | 3 +++ 6 files changed, 36 insertions(+) create mode 100644 pop/pop.js create mode 100644 pop/study-case.js create mode 100644 shift/study-case.js create mode 100644 splice/study-case.js create mode 100644 unShift/study-case.js create mode 100644 unShift/unShift.js diff --git a/pop/pop.js b/pop/pop.js new file mode 100644 index 0000000..0939fe0 --- /dev/null +++ b/pop/pop.js @@ -0,0 +1,4 @@ +let myHobby = ["play game","Harimau","read book"]; + +myHobby.pop(); +console.log(myHobby) \ No newline at end of file diff --git a/pop/study-case.js b/pop/study-case.js new file mode 100644 index 0000000..9ada348 --- /dev/null +++ b/pop/study-case.js @@ -0,0 +1,6 @@ +let animal = ["Singa", "Harimau", "Macan tutul"]; +function deleteLastIndex() { + return animal.pop(); +} +deleteLastIndex(); +console.log(animal); diff --git a/shift/study-case.js b/shift/study-case.js new file mode 100644 index 0000000..711d044 --- /dev/null +++ b/shift/study-case.js @@ -0,0 +1,7 @@ +let MyHobby = ["Running", "Hiking", "swimming"]; + +function deleteMyHobby() { + return MyHobby.shift(); +} +deleteMyHobby(); +console.log(MyHobby) \ No newline at end of file diff --git a/splice/study-case.js b/splice/study-case.js new file mode 100644 index 0000000..9e6ec25 --- /dev/null +++ b/splice/study-case.js @@ -0,0 +1,9 @@ +let animal = ["Singa","Harimau","Macan Tutul"]; + +function deleteElement(index, totalElement) { + return animal.splice(index,totalElement); +} + +deleteElement(1, 1); +console.log(animal); + diff --git a/unShift/study-case.js b/unShift/study-case.js new file mode 100644 index 0000000..5760119 --- /dev/null +++ b/unShift/study-case.js @@ -0,0 +1,7 @@ +let animal = ["Bebek", "Ayam", "Mentok", "Harimau"]; + +function AddAnimal() { + return animal.unshift("Jerapah", "Gajah"); +} +AddAnimal(); +console.log(animal); \ No newline at end of file diff --git a/unShift/unShift.js b/unShift/unShift.js new file mode 100644 index 0000000..02ce3a0 --- /dev/null +++ b/unShift/unShift.js @@ -0,0 +1,3 @@ +let animal = ["Sapi", "kerbau", "Buaya", "Harimau"]; +animal.unshift("Kelinci", "Zebra"); +console.log(animal); \ No newline at end of file From 167efc2c4b816026a864006ac33113d8c6afa95d Mon Sep 17 00:00:00 2001 From: ghianlughi Date: Wed, 27 Dec 2023 11:12:17 +0700 Subject: [PATCH 4/4] feat: add splice and shift --- array-methods/index.js | 28 ----------------- array-methods/study-case.js | 61 ------------------------------------- unShift/unShift.js | 1 + 3 files changed, 1 insertion(+), 89 deletions(-) delete mode 100644 array-methods/index.js delete mode 100644 array-methods/study-case.js diff --git a/array-methods/index.js b/array-methods/index.js deleted file mode 100644 index 8d9f7dc..0000000 --- a/array-methods/index.js +++ /dev/null @@ -1,28 +0,0 @@ -const fruits = ['Orange','Apel','watermelom','manggo']; - -fruits.push('strawberry'); - -// console.log(fruits.toString()) - - -const person = ['Budi','joni','wahyudi']; - -person.push('wiliam','Erik','Thomas'); - -// console.log(person.toString()) - -//array foreach -person.forEach(function(data){ - console.log(data) -}) - - -// daily Assigment | tugas harian - -// buat 4 array yang keudian akan di tambahkan data dengan method push() -// setelah data array di tambahkan , kalurakan data dan tampilkan dengan forEach() -// 5 array dengan nama myHobbies, myFriends,myFavouriteFoods, My,Language -// file study-case.js - - - diff --git a/array-methods/study-case.js b/array-methods/study-case.js deleted file mode 100644 index 152be3f..0000000 --- a/array-methods/study-case.js +++ /dev/null @@ -1,61 +0,0 @@ -// Daily Assigment - -// 1. Array myHobbies - -const myHobbies = ['runing', 'Basketball', 'swimingpoll']; - -myHobbies.push('cook','Watch movies'); - -console.log(myHobbies.toString()); - -myHobbies.forEach(function (data) { - console.log(data) -}) - -// 2. Array MyFiriends -const myFriends = ['Nanta', 'Dandi', 'Ghian']; - -myHobbies.push('Abi','Renata','ramzi'); - -console.log(myFriends.toString()); - -myFriends.forEach(function (data) { - console.log(data) -}) - -// 3. Array My FavoriteFoods -const myFavouriteFoods = ['fried rice', 'Dandifried duck', 'Geprek chicken']; - -myHobbies.push('soto','meatball'); - -console.log(myFavouriteFoods.toString()); - -myFavouriteFoods.forEach(function (data) { - console.log(data) -}) - -// 4. Array My Language -const myLanguage = ['Indonesia', 'Inggris']; - -myHobbies.push('Arabic','Italy'); - -console.log(myLanguage.toString()); - -myLanguage.forEach(function (data) { - console.log(data) -}) - -// 5. myGame -const myGame= ['PUBG', 'Mobile Legends']; - -myGame.push('Class of clans'); - -console.log(myGame.toString()); - -myGame.forEach(function (data) { - console.log(data) -}) - - - - diff --git a/unShift/unShift.js b/unShift/unShift.js index 02ce3a0..c0836ba 100644 --- a/unShift/unShift.js +++ b/unShift/unShift.js @@ -1,3 +1,4 @@ let animal = ["Sapi", "kerbau", "Buaya", "Harimau"]; animal.unshift("Kelinci", "Zebra"); + console.log(animal); \ No newline at end of file