Why is this function behaving differently than I expected?

Recently, I wrote a javascript code by referring to the Python code, but the result did not come out as expected. Here’s the code. const languages = [‘python’, ‘perl’, ‘c’, ‘java’]; for (let lang of languages) { if(lang == "python" || "perl") { console.log(`${lang} need interpreter`); } else if (lang == "c" || "java") {… Read More Why is this function behaving differently than I expected?

How to count the occurrences of the values of an array in a array of objects

I have an array of objects like this [ { entry: 1, answer: "[\"aaa\",\"bbb\"]" }, { entry: 2, answer: "[\"ccc\",\"bbb\"]" }, { entry: 3, answer: "[\"ccc\",\"bbb\"]" } ] Note that the value in answer is a stringified array. I would like to count how many occourrence of each answer and get back an object like… Read More How to count the occurrences of the values of an array in a array of objects

How to search an array of objects using another array of objects

I have an array of objects like this [ { "prop1": "value1", "prop2": "value1", "check": { "gender": [‘male’], "office": [‘London’,’New York’] } }, { "prop1": "value2", "prop2": "value2", "check": { "gender": [‘female’], "office": [‘Berlin’, ‘New York’] } } ] I want to search this array passing another object, that will be compared to the check… Read More How to search an array of objects using another array of objects

Is there another way to get data from an API endpoint or resolve this returned data?

I am trying to fetch data from an endpoint in my project, but continue to get a Promise back instead of the actual data. First of all I should say that I am not getting an error, however I just don’t understand why I couldn’t handle the returned data from the api call outside of… Read More Is there another way to get data from an API endpoint or resolve this returned data?

how to test if a variable has numbers javascript

I would like to know how I could test if a variable has numbers I tried with two codes but none worked. var adressevalidation = document.getElementById("adresse").value; console.log(adressevalidation); //test de l’adresse il doit y avoir un numero valable pour tous les pays if (!preg_match(‘#[\d ]#’, (adressevalidation))) { document.getElementById("myadresse").innerHTML = "pas de numero"; document.getElementById("adresse").style.backgroundColor = "red"; }… Read More how to test if a variable has numbers javascript

Why tinycolor().brighten() is not working correctly?

I am using tinycolor2, I want to get brighter colors from brandColor_Base this is how my code looked like import tinycolor from "tinycolor2" const brandColor_Base="#338EF5"; export var colors={ brandColor_1:tinycolor(brandColor_Base).brighten(70).toString(), brandColor_2:tinycolor(brandColor_Base).brighten(55).toString(), brandColor_3:tinycolor(brandColor_Base).brighten(40).toString(), brandColor_4:tinycolor(brandColor_Base).brighten(25).toString(), brandColor_5:tinycolor(brandColor_Base).brighten(10).toString(), brandColor_6:tinycolor(brandColor_Base), } but because I won’t to re-write each time tinycolor(brandColor_Base) I updated my code like below import tinycolor from "tinycolor2" const… Read More Why tinycolor().brighten() is not working correctly?

How to get a value from a setter method?

I have this setter method that I got from a YouTube video by Coding with Adam: class SpriteAnimation{ images = []; constructor(fileNameTemplate, numberOfImages, timerCount, state, stopAtEnd) { for (let i = 1; i <= numberOfImages; i++) { const image = img(fileNameTemplate.replace("?", i)); this.images.push(image); } this.timerCount = timerCount; this.timerCountDefault = this.timerCount; this.imageIndex = 0; this.state =… Read More How to get a value from a setter method?