|
| 1 | + // ------------problem 18------------ |
| 2 | + // splice = adding new items to an array |
| 3 | + // slice = removing items from an Array |
| 4 | + // splice and a given array - remove two items and adding two new elements |
| 5 | + |
| 6 | + let cars = ["audi", "farrari", "marcedes", "toyota", "volvo"]; |
| 7 | + |
| 8 | + let splice = cars.splice(2, 0, "RollsRoyes", "Tesla") |
| 9 | + console.log(cars); |
| 10 | + |
| 11 | + let players = ["tamim", "shakib", "riad", "rubel"]; |
| 12 | + |
| 13 | + let slice = players.slice(2); |
| 14 | + console.log(slice); |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + //----------------problem 19------------- |
| 20 | + //Reverse and sort an array where arr = [2,45,4,55,12,42,34,78] |
| 21 | + |
| 22 | + let newNumbers = [2,45,4,55,12,42,34,78]; |
| 23 | + |
| 24 | + console.log(newNumbers.sort(function(x, y){return x - y})); |
| 25 | + // console.log(newNumbers.reverse(function(x, y){return x - y})); //comment-out this one to see the answers for Reverse Array |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + //----------------problem 20------------- |
| 31 | + //Create an object with car and add two function in there (called methods as well) and print out the result calling two functions using this keyword as well |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + //----------------problem 21------------- |
| 36 | + //Reverse a given string. Where, - let text = “I love coding” - after reverse a string output will be - ‘gnidoc evol i’ |
| 37 | + |
| 38 | + const text = "I love coding"; |
| 39 | + |
| 40 | + let newText = ""; |
| 41 | + for(let i = text.length - 1; i >= 0; i--) { |
| 42 | + newText += text[i]; |
| 43 | + } |
| 44 | + |
| 45 | + console.log(newText); |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + //----------------problem 22------------- |
| 50 | + //Create an array with list of items. Iterate the array to view the list of the items in the console using for loop. |
| 51 | + |
| 52 | + let managers = ["karim", "rahim", "abdal", "rasel", "rajon", "charles", "Fahim"]; |
| 53 | + |
| 54 | + for (let i=0; i <= managers.length; i++) { |
| 55 | + console.log(managers[i]); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + |
0 commit comments