Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 21 2018 17:11
    @MadLittleMods banned @OmarAlmaqtri
  • Jun 05 2018 23:13
    @MadLittleMods banned @LWSS
  • May 25 2018 16:50
    @MadLittleMods banned @TheRedstoneTaco
Braulio
@bab2683
@EuphoricPenguin that is what I was trying to say, you can't really declare you are "some level of javascript" because there is always something new to learn
dimtabu
@taburetkin
actually, its true for anything in the world
EuphoricPenguin
@EuphoricPenguin
General syntax question: Is setting a variable using var foo = "bar"; and then later in the code reassigning the value without var: foo = "new value"; treated the same as using var for each value reassign?
Still, about this ^
Is setting a variable as a property after declaring it by name to be a variable syntactically the same as using var for each value reassign?
dimtabu
@taburetkin
EuphoricPenguin
@EuphoricPenguin
@taburetkin I know how to use it, all I'm asking is if var is only used the first time for reassigning values.
dimtabu
@taburetkin
actually, links i give you completely answers your question, but to get the answer you have to read
EuphoricPenguin
@EuphoricPenguin
It looked like just scope.
EuphoricPenguin
@EuphoricPenguin
@taburetkin Saw an article here, so you don't use var to reassign. I never did, but for some reason I was worried lol.
EuphoricPenguin
@EuphoricPenguin
Oh, just saw this and was curious: What is the "?" operator? Is it shorthand, I've only seen it used a couple of times.
Tried to find it on MDN and Google, no luck.
Nvm, found it.
Assigns an optional value based on condition.
Nadia
@nadiaschutz
// how would you improve this code in node.js? any suggestions? thanks
const axios = require('axios')
const chalk = require('chalk');
const url = "http://api.genderize.io"
const names = [];
let params;

for (let j = 2; j < process.argv.length; j++) {
    if (isNaN(Number(process.argv[j]))) {
        names.push(process.argv[j]);
    }
}


if (names.length === 0) {
    console.log('Please provide names');
} else if (names.length === 1) {
    params = "?name=" + names;
} else {
    const result = [];
    for (let j = 0; j < names.length; j++) {
        (j === 0) ? params = "/?name[]=" + names[j] : result.push("&name[]=" + names[j]);
    };
    result.forEach(element => {
        params += element;
    });
}


axios({
    method: 'get',
    url: url + params,
    headers: {
        'Accept': 'application/json'
    },
}).then(res => {
    checkGender(res.data);
}).catch(err => {
    const log = chalk.red(err) // we set the color red here for errors.
    console.log(log)
})

const checkGender = (data) => {
    const result = [];
    females = [];
    males = [];
    data.forEach(name => {
        name.gender === 'female' ? females.push(name) : males.push(name)
    });
    result.push(females.sort(function (a, b) {
        return b.probability - a.probability;
    }));
    result.push(males.sort(function (a, b) {
        return a.probability - b.probability;
    }));

    console.log(result);
}
Nadia
@nadiaschutz
➜ node gender.js tom jack maria anna Alexis
[ [ { name: 'anna', gender: 'female', probability: 1, count: 4755 },
    { name: 'maria',
      gender: 'female',
      probability: 0.99,
      count: 8402 } ],
  [ { name: 'Alexis', gender: 'male', probability: 0.52, count: 1224 },
    { name: 'jack', gender: 'male', probability: 0.99, count: 1993 },
    { name: 'tom', gender: 'male', probability: 1, count: 3736 } ] ]
dimtabu
@taburetkin
@nadiaschutz
const checkGender = (data) => {
    let genders = { 
        male: [1, (a,b) => a.probability - b.probability], 
        female: [-1, (a,b) => b.probability - a.probability] 
    };
    data.sort((a,b) => {
       if (a.gender == b.gender) {
          return genders[a.gender][1](a,b);
       }
       return genders[a.gender][0] - genders[b.gender][0];
    });
    console.log(data);
}
Nadia
@nadiaschutz
const checkGender = (data) => {
    let females = (data.filter(item => { return item.gender === 'female' })).sort((a, b) => {
        return b.probability - a.probability;
    });
    let males = (data.filter(item => { return item.gender === 'male' })).sort((a, b) => { return a.probability - b.probability });
    let result = [...females, ...males];

    console.log(result);
}
dimtabu
@taburetkin
i belive you can sort in one go, like in my example
without creating three additional arrays.
Nadia
@nadiaschutz
@taburetkin could you please explain what does each step do?
dimtabu
@taburetkin
sure
Nadia
@nadiaschutz
можешь на русском если удобнее
в крайнем случае на китайском
dimtabu
@taburetkin
))))
khinekhinemyatnoe
@babemyatnoe_gitlab
Hello there!:)
can someone help me?
i do need help with js codes.
i'm new and can i get a chance to get a reply?
khinekhinemyatnoe
@babemyatnoe_gitlab
i've downloaded this https://codepen.io/elmahdim/pen/tEeDn and i wanted to add their js function to my own design
nicfaust
@nicfaust
🙄 беда печаль
Abdul Basit
@Abdul___Says_twitter
@babemyatnoe_gitlab please ask, which problem are you facing ?
Richard Sithole
@Sliqric7053

Hi there

I have a 10x4 grid of checkboxes (call it x, y) - I would like to get the coordinates (x, y values) of the checkbox when a user selects one. What data structure can I use to pluck out those coordinates?

I've tried using a Map like so:

 onCheck(e) {
    const productMap = new Map();

    productMap.set('productId', e.path[2].id.split('-').pop());
    productMap.set('productLevelId', e.path[2].id.split('-').pop());
}

The checkboxes are generated dynamically, so I use a click event listener and pass in the checkbox element..

The backend expects from me, a response like this:

{
productId: 4,
productLevelId: 1
}

Any ideas how I can accomplish this?

dimtabu
@taburetkin
when you click on a checkbox then change event is emited
event.target in that case will point to your checkbox dom element
you can add additional attributes to the dom element
<input type="checkbox" data-id="yourProductId" data-levelid="yourLevelId">
and then extract this values in the change event from the event target
Richard Sithole
@Sliqric7053
@taburetkin thanks - much appreciated, lemme give it a go.
Shekhar Ramola
@shekharramola
if I do like this, would you expect array to get modified?
```
   this.myForm.value.arr.forEach(form => {
      this.filesToSend.forEach(element => {
        element = element + '=' + form.password;
        console.log(element);
      });
    });
    console.log(this.myForm);
    console.log(this.filesToSend);
  }
```
inside it is getting modified but no effect on filestosend array
Stephen James
@sjames1958gm
If element is a reference to the value in the array, you are changing the vale of the reference not the value being referred to. So no it would not change the array
Remove that first ‘if’ in the above sentence
Shekhar Ramola
@shekharramola
if statement is not there. where it is?
yousefMZ
@yousefMZ
what is the code in codewars ?? javascriptfunction multiply(a, b){
a * b
}
Stephen James
@sjames1958gm
@shekharramola oh lol, I meant the ‘if’ in my response not in your post.
Jefferson
@jeffersonnnn
hey guys
EuphoricPenguin
@EuphoricPenguin
this is Austin
syedsimanta03
@syedsimanta03
import store from './store/store';

console.log('Before:', store.getState());
sometimes in Node or React we use store.getState() and sometimes store.getState. Without direct invoking, why is that? what is the difference? Thanks