28th
Apr 2018
Apr 28 2018 00:47
Damn had to throw out like 2 hours of work cuse I took the wrong approach :'(
Lev Karatun
@lkaratun
Apr 28 2018 06:05
Hi everyone, could someone have a look at my solution to one of the exercises? Can't figure out why it's not accepted =/
Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).
Here's my solution:
function findElement(arr, func) {
arr.forEach(i => {
if (func(i)) return i;
});
}
Lev Karatun
@lkaratun
Apr 28 2018 06:11
nevermind, I figured it out
JJ Megma
Apr 28 2018 07:18
@lkaratun if (func(i)) return i; i think is ur problem
JJ Megma
Apr 28 2018 07:30
I'm guessing you want to find the index of the element that returns true on the callback function
JJ Megma
Apr 28 2018 07:35
@lkaratun going with your strategy, heres a way to go about it :)
``````function findElement(arr, func) {
var result;
arr.forEach((el,i) => {
if(func(el)){
result = i
} else{
result = -1
}
});
return result
}

findElement([1,2,3], (x)=>{
return x === 3
})``````
Rajat
@rajataudichya
Apr 28 2018 08:55
@bradtaniguchi what is the use of ternary operators?
Kudzu
@czhower
Apr 28 2018 12:37
ternary ops allow shorter code, syntactic sugar
dhx825626719
@dhx825626719
Apr 28 2018 12:56

var result = "";
// 请把你的代码写在这条注释以下

// 请把你的代码写在这条注释以上
return result;
}

wordBlanks("dog", "big", "ran", "quickly"); /

I DONT Know it
who can tell me?
Norvin Burrus
@ndburrus
Apr 28 2018 14:14
@dhx825626719

Stephen James
@sjames1958gm
Apr 28 2018 14:23
@rajataudichya ternary operator also is an expression which can return a value.
Can make some code shorter and clearer, but can make some code shorter and less clear.
`var x = test ? val1 : val2` you can assign the result of ternary which you cannot with `if`
mstellaluna
@mstellaluna
Apr 28 2018 14:38
@ndburrus Only the Chinese and the Espanol rooms exist, that list is out of date :)
Norvin Burrus
@ndburrus
Apr 28 2018 14:41
@mstellaluna ...i just visited the room and the last post was at 9:52am (today). it appears to be enabled...
mstellaluna
@mstellaluna
Apr 28 2018 14:42
@ndburrus which one?
The Chinese and Espanol (Spanish room) are the only 2 left from that the world language list
Norvin Burrus
@ndburrus
Apr 28 2018 14:48
@mstellaluna thanks... noted. :smile:
mstellaluna
@mstellaluna
Apr 28 2018 14:48
:)
Rajat
@rajataudichya
Apr 28 2018 14:54
@sjames1958gm EXAMPLE?
Stephen James
@sjames1958gm
Apr 28 2018 16:32
@rajataudichya There is an example in my post above. A more specific example?
Tiago Correia
@tiagocorreiaalmeida
Apr 28 2018 16:48
Smootimus
@Smootimus
Apr 28 2018 22:14
Le sigh
eeflores
@eeflores
Apr 28 2018 22:39
Le sigh?
Smootimus
@Smootimus
Apr 28 2018 22:43
Yeah I was gettin' a little frustrated with somethin
But it's settled now, I got what I was waiting for
eeflores
@eeflores
Apr 28 2018 22:53
yay!