These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Sep 2017
Diego Mayer
@Chrono79
Sep 16 2017 01:16
@legendinraze if val is a number, then it's either bigger than 5 or equal or smaller than 5
test for one of the 2 conditions and use the else in the other case
duqingmei
@duqingmei
Sep 16 2017 02:12
Create a JavaScript Slot Machine
kumquatfelafel
@kumquatfelafel
Sep 16 2017 02:13
What if I don't want to? :o
duqingmei
@duqingmei
Sep 16 2017 02:13
<script>
function runSlots() {
var slotOne;
var slotTwo;
var slotThree;
var images = ["//i.imgur.com/9H17QFk.png", "//i.imgur.com/9RmpXTy.png", "//i.imgur.com/VJnmtt5.png"];

// 请把你的代码写在这条注释以下



// 请把你的代码写在这条注释以上


if (slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined) {
  $(".logger").html(slotOne + " " + slotTwo + " " + slotThree);
}
kumquatfelafel
@kumquatfelafel
Sep 16 2017 02:13
:p
on a serious note, do you have a link handy? Not seeing this anywhere.
Ronique Ricketts
@RoniqueRicketts
Sep 16 2017 02:59
Reactjs is so cool. If only I could setState () on my bank account to a few millions
kumquatfelafel
@kumquatfelafel
Sep 16 2017 04:32
@RoniqueRicketts Whoever said you can't? It's never too late to try! :o
pahosler
@pahosler
Sep 16 2017 05:32
anyone super react savvy in here this evening?
kumquatfelafel
@kumquatfelafel
Sep 16 2017 05:48
Not entirely sure anyone's here. Can't hurt to just ask whatever question you had though.
@pahosler
pahosler
@pahosler
Sep 16 2017 05:54
talking to some folks in the main channel, thank you for replying :D
Mohammed Boudad
@matrixersp
Sep 16 2017 10:12
Can someone tell me why this doesn't work? It worked for me in VS Code but not in the test
count=0;
function permute(prefix, str) {
  if(str.length === 0 && ! prefix.match(/(.)\1/g)) {
    count++;
  }
  for(var i = 0; i < str.length; i++) {
    permute(prefix + str[i], str.substr(0, i) + str.substr(i+1, str.length - 1))
  }
  return count;
}

function permAlone(str) {
    return permute("", str);
}
permAlone('aba');
Pieter Stokkink
@forkerino
Sep 16 2017 10:15
@matrixersp probably because you have a global variable. This won't get reset between the tests
So you'll keep on counting
You can probably move it inside the permute function and make some minor alterations
to make it work
linkin-park
@linkin-park
Sep 16 2017 12:12
what is DOM
Pieter Stokkink
@forkerino
Sep 16 2017 12:19
@linkin-park Document Object Model.
it is kinda like the HTML that shows on a webpage
or rather, it is a JS handle for the HTML, so you can add/change/remove stuff on the page
LydaTech
@lydatech
Sep 16 2017 12:22
@linkin-park It defines the logical structure of documents and the way a document is accessed and manipulated
linkin-park
@linkin-park
Sep 16 2017 12:26
so what does javascript engine does ?
pulls the data ? often
Pieter Stokkink
@forkerino
Sep 16 2017 12:29
the js engine simply executes the javascript
but it also provides access to the DOM
LydaTech
@lydatech
Sep 16 2017 12:54
Big3_Explain.PNG
linkin-park
@linkin-park
Sep 16 2017 13:35
is it possible to remove js from browser ?
and add our own lang in ?
Pieter Stokkink
@forkerino
Sep 16 2017 13:36
@linkin-park you can disable it, but not much of the web remains after doing that.
that last question: not really, your browser would need to understand that language.
linkin-park
@linkin-park
Sep 16 2017 13:55
is it possible to get remote jobs via FCC ?
linkin-park
@linkin-park
Sep 16 2017 14:09
wrong place to ask :(
i lost my job (i quit since it was boring and no future) 7 months back :/ thinking now how to do things :(
Pieter Stokkink
@forkerino
Sep 16 2017 14:12
@linkin-park FCC is not a job board, but the skills will help you get a job once you are ready for it.
linkin-park
@linkin-park
Sep 16 2017 14:28
i'm looking for senior engineer :/ can this helps (doubt)
@forkerino
i just got carried away sorry :(
Lance
@texas2010
Sep 16 2017 14:32
@linkin-park i dont know why you think fcc is a job board but it is not. fcc is a site for learn skills.
linkin-park
@linkin-park
Sep 16 2017 14:34
i know it but what type of skill will i learn matters right ?
sorry guys thanks for helping me out :)
Pethaf
@Pethaf
Sep 16 2017 14:37
@linkin-park Are you located in the US?
linkin-park
@linkin-park
Sep 16 2017 14:45
nope
k i'm going to do something crazy :) thanks all
Pethaf
@Pethaf
Sep 16 2017 14:57
Otherwise udacity might be something for you.
kumquatfelafel
@kumquatfelafel
Sep 16 2017 15:13
@forkerino I mean technically, I suppose you could throw another language on top of the javascript, or create your own browser ... but it would still have to be able to interpret javascript, otherwise, who would want to use your lousy browser? :p
(Either way, there's no escaping javascript... in web, anyway)
linkin-park
@linkin-park
Sep 16 2017 15:17
atleast i can start my startup :) @Pethaf after FCC :smile:
Pethaf
@Pethaf
Sep 16 2017 15:48
@kumquatfelafel I want to say webasm.
kumquatfelafel
@kumquatfelafel
Sep 16 2017 16:08
@Pethaf Well, in the future, potentially. But these browsers still support javascript. My point was that since js is so widespread, support for it would still be necessary, even if you added a different language. If you got rid of javascript entirely today, things could potentially still function, provided you still interpreted that into a useable language (in which case, you wouldn't really be getting rid of it). If you didn't, it would be Webpocalypse.
linkin-park
@linkin-park
Sep 16 2017 16:21
wish there was folder under gist :)
WAINGOR
@WAINGOR
Sep 16 2017 17:22
Hi all, can somebody please explain to me how this is possible?The code below results in an array full of arrays... How?! I just ask it to put numbers 1 until 4 into it?!
var arr= [4,1];
var smallToBig = function(a,b) {
return a-b;
};
var arraySorted = arr.sort(smallToBig);
console.log('after sort ArraySort is '+ arraySorted);


//set up arrays and variables representing numbers
//
var bigNumbers = [];
var smallNumbers = [];
var inBetween = [];

var turnOff = false;
console.log('first el is ' + arraySorted[0] );
//make array of inBetween numbers
for (var i=arraySorted[0]; i<=arraySorted[1]; i++) {
   inBetween.push([i]);

}

console.log(Array.isArray(inBetween[0]));
lol never mind
silly mistake
thanks WAINGOR!!! Camperbot sends 3022933 browny points to WAINGOR
LydaTech
@lydatech
Sep 16 2017 17:41
WAINGOR sends brownie points to @WAINGOR :sparkles: :thumbsup: :sparkles:
GODMODE UNLOCKED
linkin-park
@linkin-park
Sep 16 2017 17:42
i like to add few more algo whom to contact ?
linkin-park @linkin-park watching movie ^^ out
linkin-park
@linkin-park
Sep 16 2017 18:31

@WAINGOR , is this good solution ?
function sumAll(arr) {
return lpsum(arr.reduce((tot,curr)=>tot<curr?tot:curr), arr.reduce((tot,curr)=>tot>curr?tot:curr));
}

lpsum = function(min,max){
if(min==max) return min;
return max+lpsum(min,max-1);
}; // excluded negative shit!

马文龙
@peoplewhoneedstruggle
Sep 16 2017 20:09
var myPlants = [
{
type: "flowers",
list: [
"rose",
]
},
{
type: "trees",
list: [
"fir",
]
}
];
// 请只修改这条注释以下的代码
var secondTree = myPlants ; // 请修改这一行
//My question is how to access the "tree"'s value,
// I want secondTree'value ="fir",how can do that ?
korzo
@korzo
Sep 16 2017 20:12
@peoplewhoneedstruggle myPlants[1].type
var secondTree = myPlants[1].list[0]
马文龙
@peoplewhoneedstruggle
Sep 16 2017 20:17
It's very kind of you,thank you! @korzo
CamperBot
@camperbot
Sep 16 2017 20:17
peoplewhoneedstruggle sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 493 | @korzo |http://www.freecodecamp.com/korzo
Kelechi Chinaka
@ke1echi
Sep 16 2017 21:12
Array.prototype.removeValue = function(thing) {
  console.log(this,thing)
  if (!this.includes(thing)) return false;
  for (let i = 0; i < this.length; i++) {
    if (this[i] === thing) this.splice(i, 1,"");
  }
  return this;
}
`Expected: '[2, 3]', instead got: '[\'\', 2, 3, \'\']'
what am i doing wrong
Joel Y.
@zapcannon99
Sep 16 2017 21:16
I don't think you need the "" in this.splice(i, 1) if you are just deleting an element
Though I don't think that solves your problem
korzo
@korzo
Sep 16 2017 21:17
@kelechy use filter and return result
also why you have "" in splice() ?
Kelechi Chinaka
@ke1echi
Sep 16 2017 21:20
no use of any other method apart from splice for the challenge
korzo
@korzo
Sep 16 2017 21:21
@kelechy Could you post instruction?
should you replace thing with empty value or remove it?
Kelechi Chinaka
@ke1echi
Sep 16 2017 21:21
i know that but i dont know what this.splice(i, 1) failed 1 test @zapcannon99
Joel Y.
@zapcannon99
Sep 16 2017 21:23
but this.splice(i,1) is how you would remove an element in an array
Joel Y.
@zapcannon99
Sep 16 2017 21:24
It passed all the tests for me
nvm, I didn't hit the right button
One issue i see is that when you remove an element, you don't want to immediately go on the the next index

for example:
[a, b, c, d]
if want to remove a, which is index 0 we get:

[b, c, d]

The question is though, if we are using a for loop do we want to go on to check index=1, or because we removed an element, should we check index=0 again? I think you know the answer.

Kelechi Chinaka
@ke1echi
Sep 16 2017 21:28
i dont
korzo
@korzo
Sep 16 2017 21:32
@zapcannon99 this. you can't use for loop
Array.prototype.removeValue = function(thing) {

    if (this.length === 0 || !this.includes(thing)) {
      return false;
    }

    var i = 0;

    while(i < this.length) {
      if (this[i] === thing) {
        this.splice(i, 1);        
      } else {
        i++;
      }    
    }    
    return this;
}
Kelechi Chinaka
@ke1echi
Sep 16 2017 21:42
function remove_(arr,thing) {
  if (!arr.includes(thing)) return false;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === thing) arr.splice(i--, 1);
  }
  return arr;
}
Joel Y.
@zapcannon99
Sep 16 2017 22:15
@korzo you can
korzo
@korzo
Sep 16 2017 22:15
@zapcannon99 Of course.
Joel Y.
@zapcannon99
Sep 16 2017 22:15
I passed all tests only modifying Kelechy's code in two lines
@Kelechi you need to add an extra line of code under the second if statement, not change the element you are deleting
korzo
@korzo
Sep 16 2017 22:17
@zapcannon99 I was not exact. I meant that you have to move pointer back if thing is found
Joel Y.
@zapcannon99
Sep 16 2017 22:17
ah, then yes, you're correct. Gotta make sure that index is pointing to the correct place
korzo
@korzo
Sep 16 2017 22:21
@zapcannon99 I think his code is correct.
I went with for loop also, because it's 1 line shorter then while loop
Joel Y.
@zapcannon99
Sep 16 2017 23:08
The last one he posted is not. If the first element matched thing, then we have a problem when it tries to delete -1
korzo
@korzo
Sep 16 2017 23:11
@zapcannon99 no, because it's i--
at first it run splice and then it decrements i
Problem would be with --i
@zapcannon99 try
function remove_(arr,thing) {
  if (!arr.includes(thing)) return false;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === thing) arr.splice(i--, 1);
  }
  return arr;
}

console.log(remove_([2,1, 2,1,2, 2, 2, 3], 2));
I ended up with this
Array.prototype.removeValue = function(thing) {
  return this.includes(thing) && ((() => {    
    while(this.includes(thing)) this.splice(this.indexOf(thing), 1);
  })() || this);
}
Joel Y.
@zapcannon99
Sep 16 2017 23:38
ah good point, yeah your right. whoops