Snippets Collections
(function () {
  "use strict";

  // object instead of switch

  // check for oddf or even number using the function insides the object
  const options = {
    odd: (item) => item % 2 === 1,
    even: (item) => item % 2 === 0,
  };

  const number = 7;
  const checkValue = "odd";

  const checked = options[checkValue](number); // returns true of false
  if (checked) {
    console.log(number);
  }

  const testArray = [3, 4, 5, 6, 8, 0, 12, 40, 12, 3];

  function filterArray(array, position) {
    return array.filter((item) => options[position](item));
  }

  const getOdd = filterArray(testArray, "odd");
  console.log("Odd", getOdd);

  const getEven = filterArray(testArray, "even");
  console.log("Even", getEven);
})();
import React from "react";
import ReactDOM from "react-dom";

class App extends React.Component {
  render() {
    return [
      {
        name: "Sam",
        email: "somewhere@gmail.com",
        public: false
      },

      {
        name: "Ash",
        email: "something@gmail.com",
        public: true
      }
    ].map((anObjectMapped, index) => {
      return anObjectMapped.public ? (
        <p key={`${anObjectMapped.name}_{anObjectMapped.email}`}>
          {anObjectMapped.name} - {anObjectMapped.email}
        </p>
      ) : null;
    });
  }
}

ReactDOM.render(<App />, document.getElementById("container"));
People = 30
Cars = 40
Trucks = 14
# line 1,2,3 assign the value to variables
If cars > people: Using if statement
  Print(“we should take the  cars.”)
Elif cars < people: if 1st is false execute elif
  print(“we should not take the car.”)
else : # if both are false then execute else:
    print(“we can’t decide.”)
                               
                                
star

Sat Mar 08 2025 05:42:25 GMT+0000 (Coordinated Universal Time)

#swtich #object #condition
star

Mon May 02 2022 17:13:08 GMT+0000 (Coordinated Universal Time)

#condition #ifelse #operator
star

Tue Apr 21 2020 11:15:59 GMT+0000 (Coordinated Universal Time) https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp/0321884914

#python #python #condition #ifstatement #elifstatement #elsestatement

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension