Skip to content

Commit

Permalink
Info: moved array programs to separate section
Browse files Browse the repository at this point in the history
  • Loading branch information
Koushikon committed Mar 12, 2023
1 parent c080061 commit 0e62d54
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 02.Arrays/Array_reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* ? Syntax: Array_name.reverse()
* * Array One Method reverses the original array.
* ? Syntax: [...Array_name].reverse()
* * Array Another Method keeps the original array as it is and creates a new array of reversed elements.
*/

const names_1 = ["Alice", "Bob", "Charlie", "David"]
const reversed_1 = names_1.reverse()

// Output: David, Charlie, Bob, Alice
console.log(names_1)
// Output: David, Charlie, Bob, Alice
console.log(reversed_1)



const names_2 = ["Alice", "Bob", "Charlie", "David"]
const reversed_2 = [...names_2].reverse()

// Output: Alice, Bob, Charlie, David
console.log(names_2)
// Output: David, Charlie, Bob, Alice
console.log(reversed_2)
30 changes: 30 additions & 0 deletions 02.Arrays/Arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Array Elements:
* -5 Index: 10
* -4 Index: 6
* -3 Index: 7
* -2 Index: 8
* -1 Index: 9
*/
var Nums = [10, 6, 7, 8, 9];
console.log(Nums.at(-5));

/**
* * Array Destructurig:
*/
const states = ["Abia", "Adamawa", "Anambra", "Bauchi", "Bayelsa", "Benue", "Borno", "Cross River", "Delta", "Ebonyi", "Enugu", "Edo"];

// Getting values from start and with few skip
const [first, second, , fourth] = states;
console.log(first, second, fourth)

// Getting only specified position values
const { 2: third, 5: fifth, 9: tenth } = states;
console.log(third, fifth, tenth);


const my = { name: 'Random People', company: 'Andela' };
const { name } = my;
console.log(name);
const { name: Human } = my;
console.log(Human);

0 comments on commit 0e62d54

Please sign in to comment.