Skip to content

Instantly share code, notes, and snippets.

@anibal21
Last active May 23, 2022 00:04

Revisions

  1. anibal21 revised this gist May 23, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions jdfArrays.js
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,12 @@ let yearTemperature = [40, 44, 40, 34, 30, 28, 26, 25, 28, 39, 35, 38]
    console.log(yearTemperature.some((temp) => temp > 40)) // There is at least one element over 40 degrees
    console.log(yearTemperature.every((temp) => temp % 2)) // false - not every number is mod 2

    // Find and FindIndex
    let yearTemperature = [40, 44, 40, 34, 30, 28, 26, 25, 28, 39, 35, 38]
    console.log(yearTemperature.find((temp) => temp === 40)) // 40 the first value
    console.log(yearTemperature.findIndex((temp) => temp === 40)) // 0 the first encountered





  2. anibal21 revised this gist May 23, 2022. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion jdfArrays.js
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,14 @@ let arrayFrom = Array.from(literalArray) // copy of [1,2,3]
    // Creating and Updating at the same time
    let rankings = [0, 100, 40, 20, 40, 343, 32, 22]
    let copy = Array.from(rankings, (r) => r % 10 === 0 ? r : 0)
    console.log(copy) // [0, 100, 40, 20, 40, 0, 0, 0]
    console.log(copy) // [0, 100, 40, 20, 40, 0, 0, 0]

    // Some and Every
    let yearTemperature = [40, 44, 40, 34, 30, 28, 26, 25, 28, 39, 35, 38]
    console.log(yearTemperature.some((temp) => temp > 40)) // There is at least one element over 40 degrees
    console.log(yearTemperature.every((temp) => temp % 2)) // false - not every number is mod 2




    /* End*/
  3. anibal21 revised this gist May 22, 2022. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions jdfArrays.js
    Original file line number Diff line number Diff line change
    @@ -21,3 +21,8 @@ let spreadOperatorArrays = [...literalArray] // copy of [1,2,3]
    let arrayConstructor = new Array()
    let arrayOf = Array.of(1,2,3) // [1,2,3]
    let arrayFrom = Array.from(literalArray) // copy of [1,2,3]

    // Creating and Updating at the same time
    let rankings = [0, 100, 40, 20, 40, 343, 32, 22]
    let copy = Array.from(rankings, (r) => r % 10 === 0 ? r : 0)
    console.log(copy) // [0, 100, 40, 20, 40, 0, 0, 0]
  4. anibal21 revised this gist May 22, 2022. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions jdfArrays.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /**
    * Theory:
    -JavaScript are unordered
    -Arrays in JavaScript are an ordered collection of values
    -Its elements are untyped, an array can contain different types of data
    -Arrays are 32-bit indexed so its index can be from 0-4294967294 (2^32 - 2)
    and its elements can go from 0 to 4.294.967.295
    @@ -13,4 +13,11 @@
    let names = ["Anibal", "Peter"]
    console.log(names.length) // 2
    names[10] = "Lucas"
    console.log(names.length) // 11
    console.log(names.length) // 11

    //Creating arrays
    let literalArray = [1,2,3]
    let spreadOperatorArrays = [...literalArray] // copy of [1,2,3]
    let arrayConstructor = new Array()
    let arrayOf = Array.of(1,2,3) // [1,2,3]
    let arrayFrom = Array.from(literalArray) // copy of [1,2,3]
  5. anibal21 created this gist May 22, 2022.
    16 changes: 16 additions & 0 deletions jdfArrays.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /**
    * Theory:
    -JavaScript are unordered
    -Its elements are untyped, an array can contain different types of data
    -Arrays are 32-bit indexed so its index can be from 0-4294967294 (2^32 - 2)
    and its elements can go from 0 to 4.294.967.295
    */

    /**
    * Relevant Examples
    */
    // Dynamic Sizing
    let names = ["Anibal", "Peter"]
    console.log(names.length) // 2
    names[10] = "Lucas"
    console.log(names.length) // 11