Skip to content

Instantly share code, notes, and snippets.

View elisavetTriant's full-sized avatar
👩‍💻
Hello there!

Elissavet Triantafyllopoulou elisavetTriant

👩‍💻
Hello there!
View GitHub Profile
@elisavetTriant
elisavetTriant / LeafletMap.js
Created September 12, 2022 20:40
Custom Leaflet Map with WordPress ACF Fields
import L from "leaflet"; //don't forget to install Leaflet with npm install leaflet
class LeafletMap {
constructor() {
document.querySelectorAll(".leaflet-map").forEach(el => {
this.new_map(el);
})
}
new_map($el) {
//#3 create two classes: an Animal class and a Mamal class.
// create a cow that accepts a name, type and color and has a sound method that moo's her name, type and color.
class Animal {
constructor(name, type, color) {
this.name = name;
this.type = type;
this.color = color;
}
}
function convertNumberToUnits(n) {
let numberToBreakUp = n.toString();
let unitsArray = numberToBreakUp.split("");
return unitsArray.map((item, index, array) => {
let zeros = '0'.repeat(array.length - index - 1);
return parseInt(item.concat(zeros), 10);
}
);
}
/*JavaScript Algorithms and Data Structures Projects: Palindrome Checker
Return true if the given string is a palindrome. Otherwise, return false.
A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.
We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others.
We'll also pass strings with special symbols, such as "2A3*3a2", "2A3 3a2", and "2_A3*3#A2".
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker*/
function palindrome(str) {
/*Intermediate Algorithm Scripting: Arguments Optional
Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.
For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
Calling this returned function with a single argument will then return the sum:
var sumTwoAnd = addTogether(2);
sumTwoAnd(3) returns 5.
If either argument isn't a valid number, return undefined.
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator*/
/*
Intermediate Algorithm Scripting: Make a Person
Fill in the object constructor with the following methods below:
getFirstName() getLastName() getFullName() setFirstName(first) setLastName(last) setFullName(firstAndLast)
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person/
*/
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
var names = firstAndLast.split(" ");
/*Intermediate Algorithm Scripting: Map the Debris
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
You can read about orbital periods on Wikipedia.
The values should be rounded to the nearest whole number. The body being orbited is Earth.
The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2.
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris*/
function orbitalPeriod(arr) {
const GM = 398600.4418; //in km3s-2.
/*Intermediate Algorithm Scripting: Everything Be True
Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
In other words, you are given an array collection of objects.
The predicate pre will be an object property and you need to return true if its value is truthy. Otherwise, return false.
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
https://www.sitepoint.com/javascript-truthy-falsy/
*/
function truthCheck(collection, pre) {
/*
Intermediate Algorithm Scripting: Binary Agents
Return an English translated sentence of the passed binary string.
The binary string will be space separated.
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents
More on converting between binary and readable strings on: https://ourcodeworld.com/articles/read/380/how-to-convert-a-binary-string-into-a-readable-string-and-vice-versa-with-javascript*/
function binaryAgent(str) {
return str.split(" ").map(function (elem) {
return String.fromCharCode(parseInt(elem, 2));
/*Intermediate Algorithm Scripting: Steamroller
Flatten a nested array. You must account for varying levels of nesting.
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller
*/
function steamrollArray(arr) {
// I'm a steamroller, baby
let tempArray = [];
for (let i=0; i < arr.length; i++){
if (Array.isArray(arr[i])){