get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
darrenfj sends brownie points to @manish-giri and @gersho and @github-henry and @faraco and @sjames1958gm and @daddycardona and @ericmiller777 and @alexanderkopke and @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1665 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
:cookie: 312 | @ericmiller777 |http://www.freecodecamp.com/ericmiller777
:cookie: 371 | @github-henry |http://www.freecodecamp.com/github-henry
:star2: 6621 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 1499 | @thekholm80 |http://www.freecodecamp.com/thekholm80
:cookie: 520 | @gersho |http://www.freecodecamp.com/gersho
:cookie: 370 | @daddycardona |http://www.freecodecamp.com/daddycardona
:star2: 8517 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 378 | @faraco |http://www.freecodecamp.com/faraco
thekholm80 sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2087 | @darrenfj |http://www.freecodecamp.com/darrenfj
@DarrenfJ no, thank you
i didn't notice the comma at first lol
gersho sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2088 | @darrenfj |http://www.freecodecamp.com/darrenfj
manish-giri sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2089 | @darrenfj |http://www.freecodecamp.com/darrenfj
github-henry sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2090 | @darrenfj |http://www.freecodecamp.com/darrenfj
longnt80 sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2091 | @darrenfj |http://www.freecodecamp.com/darrenfj
ctx.rect(window.innerWidth / 2,window.innerHeight / 2,60,120);
is this the right way to center a canvas rectangle in the middle of the screen?
kingwindie sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 206 | @piteto |http://www.freecodecamp.com/piteto
canvas.parentNode.style.textAlign = "center"
```
{
"name": "fcc-learn-npm-package-json",
"dependencies": {
"express": "^4.14.0"
},
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"engines": {
"node": "4.4.5"
},
"repository": {
"type": "git",
"url": "https://idontknow/todo.git"
},
"author": "Author"
}
```
"author": {
"name": "Nicholas C. Zakas",
"email": "nicholas+npm@nczconsulting.com"
},
name
field is required, email is optional. https://docs.npmjs.com/files/package.json#people-fields-author-contributors
heroiczero sends brownie points to @manish-giri and @darrenfj and @longnt80 and @github-henry and @piteto and @gersho and @faraco :sparkles: :thumbsup: :sparkles:
:cookie: 372 | @github-henry |http://www.freecodecamp.com/github-henry
:cookie: 522 | @gersho |http://www.freecodecamp.com/gersho
:cookie: 379 | @faraco |http://www.freecodecamp.com/faraco
:cookie: 591 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 2092 | @darrenfj |http://www.freecodecamp.com/darrenfj
:star2: 6624 | @manish-giri |http://www.freecodecamp.com/manish-giri
:cookie: 208 | @piteto |http://www.freecodecamp.com/piteto
github-henry sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1827 | @heroiczero |http://www.freecodecamp.com/heroiczero
longnt80 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1828 | @heroiczero |http://www.freecodecamp.com/heroiczero
var result = [];
result.push(/*Slice from array*/);
.slice()
should return arrays, so you then have those to .push()
to the result array - post your code if you have more questions.
i
in your for loop - so you need i = i + size
or i += size
- otherwise your loop will not end!
end
parameter that you pass to .slice()
has to be a larger index than the start
parameter - size
will always be the same. You have to calculate some other value that is larger relative to the i
value... that is, if your i
is 2, you have a size of 2, you want end
to be greater than 2.
@Seahchye - well, you are using i
for the begin
argument. And the end
argument is related to the begin
argument combined with size
. And the documentation for .slice()
says:
The
slice()
method returns a shallow copy of a portion of an array into a new array object selected frombegin
toend
(end
not included). The original array will not be modified.
So you just calculate a value for end
based on begin
(which you are generating with i
) and the size
....
seahchye sends brownie points to @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 3343 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 8518 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
mbmontana sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2093 | @darrenfj |http://www.freecodecamp.com/darrenfj
darrenfj sends brownie points to @github-henry and @marmiz and @heroiczero and @manish-giri and @gersho and @faraco and @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 374 | @github-henry |http://www.freecodecamp.com/github-henry
:star2: 1054 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 1832 | @heroiczero |http://www.freecodecamp.com/heroiczero
:cookie: 380 | @faraco |http://www.freecodecamp.com/faraco
:star2: 3344 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 6625 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 8519 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 523 | @gersho |http://www.freecodecamp.com/gersho
khaduch sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2094 | @darrenfj |http://www.freecodecamp.com/darrenfj
_.flatten(arr)
would do what I need it to do for the steam roller exercise , unfortunately I can not use it because I can not use document.write(the site for underscore js)
on the stupid fcc challenge dammit lol
daddycardona sends brownie points to @github-henry and @marmiz and @heroiczero and @manish-giri and @gersho and @faraco and @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1055 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 1833 | @heroiczero |http://www.freecodecamp.com/heroiczero
:star2: 6626 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 8520 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 375 | @github-henry |http://www.freecodecamp.com/github-henry
:cookie: 524 | @gersho |http://www.freecodecamp.com/gersho
:star2: 3345 | @khaduch |http://www.freecodecamp.com/khaduch
:cookie: 381 | @faraco |http://www.freecodecamp.com/faraco
daddycardona sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2095 | @darrenfj |http://www.freecodecamp.com/darrenfj
darrenfj sends brownie points to @daddycardona :sparkles: :thumbsup: :sparkles:
:cookie: 371 | @daddycardona |http://www.freecodecamp.com/daddycardona
function steamrollArray(arr) {
// I'm a steamroller, baby
var flattened = arr.reduce(function(a, b) {
return a.concat(b);
}, []);
console.log(flattened)
//return x;
}
},[] <--);
1
1
:
2
2
:
3
3
:
Array(1)
0
:
4
.reduce()
is really powerful - but I think that you need a recursive call for this? I haven't thought about using .reduce()
for this...
[1,2,3,[[4]]]
still
a.concat(b)
is not a function and I am like yes it is, but i needed to add the }[]
// this [recursivity [is [driving [me [nuts]]]]]
return newArr;
}
steamrollArray([1, [2], [3, [[4]]]]);
},[]
[1,2,3,[[4]]
how do i get taht sucker down again so I used another variable and just redid the reduce function again but nope that did not work lol
var na = _.flatten(arr)
and it works like a charm
:cookie: 212 | @piteto |http://www.freecodecamp.com/piteto
daddycardona sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
var s = document.createElement('script');
s.src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js";
document.body.appendChild(s);
let count = 0;
function arrayFlatten(arr){
if (count++ > 200) {
console.log("looks like a loop");
return;
}
if (Array.isArray(arr)){
console.log(`Found an array: ${JSON.stringify(arr)}`);
for (let i=0; i < arr.length; i++){
arrayFlatten(arr[i]);
}
} else {
console.log(`Not an array: ${JSON.stringify(arr)}`);
return;
}
}
arrayFlatten([1,[2,3],4,5,[[6]]]);
for
loop. If it doesn't find an array, it will just print the element.
varName.for()
console.log
it... AND it's a javascript feature, at least it's documented on MDN...
[1,etc..
but I just stringify it 1st would it not just be 1 2 3 4? when I document.write it it shows up like 1,2,3,4
console.log
outputs, since I never really figured out when I see the actual text format of the array / object, or it just outputs [Object object]
sometimes... :)
console.log(arr+'bla')
@daddycardona - this is the output that I get for that example that I put in to call my function:
"Found an array: [1,[2,3],4,5,[[6]]]"
"Not an array: 1"
"Found an array: [2,3]"
"Not an array: 2"
"Not an array: 3"
"Not an array: 4"
"Not an array: 5"
"Found an array: [[6]]"
"Found an array: [6]"
"Not an array: 6"
So when it says "Found an array", then it calls the function again, by assuming that you have an array to loop through. When it says "Not an array", that is something that was "flattened".
for(; ; ){
if(Array.isArray(arr[i])){
newArr.push(arr[i]);
}
}
daddycardona sends brownie points to @darrenfj and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2096 | @darrenfj |http://www.freecodecamp.com/darrenfj
:star2: 3346 | @khaduch |http://www.freecodecamp.com/khaduch
github-henry sends brownie points to @daddycardona and @darrenfj :sparkles: :thumbsup: :sparkles:
:cookie: 372 | @daddycardona |http://www.freecodecamp.com/daddycardona
:star2: 2097 | @darrenfj |http://www.freecodecamp.com/darrenfj
artbohr sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8521 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
function firstRepeatingLetter(str){
for(var i = 0; i<str.length; i++){
var remaining = str.slice(i+1);
if(remaining.indexOf(str[i]) !== -1) {
return str[i];
}
}
return str;
}
firstRepeatingLetter("Repetition") // => "e"
str += str
function firstRepeatingLetter(str){
for(var i = 0; i<str.length; i++){
var remaining = str.slice(i+3);
console.log(remaining);
if(remaining.indexOf(str[i]) !== -1) {
return str[i];
}
}
return str;
}
firstRepeatingLetter("Repetition") // => "e"
etition
tition
ition
tion
ion
on
n
=> 'Repetition'
leonaaa sends brownie points to @artbohr :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @artbohr |http://www.freecodecamp.com/artbohr
leonaaa sends brownie points to @artbohr :sparkles: :thumbsup: :sparkles:
hijerboa sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 213 | @piteto |http://www.freecodecamp.com/piteto