vadim9999 / js

2 stars 0 forks source link

Chapter 4 Loops & itteration #1

Open atherdon opened 6 years ago

atherdon commented 6 years ago

When you'll read this chapter, please explain what you've learned here

vadim9999 commented 6 years ago

I have learned about loops. for for (var i; i < 3; i++) { console.log(i); } while var i; while (i<3){ i++; } when condition in while will be false it's stop a loop. As the same do while. do{ i++; }while(i<3); Labels make: console.log("Hello"); go: console.log("Go"); continue make; "break" returns from a block code in curly brakes({}). if the brake statement was in loop it returns from. for in for(var i in obj){ console.log(obj[i]); } In console print all value of properties in object. i - name property obj - object for of var array = [1,2,3] for(var i of array){ console.log(i); } i - it's a value of array

atherdon commented 6 years ago

@vadim9999 read this too - nice article: https://codeburst.io/all-about-javascript-arrays-in-1-article-39da12170b1c

vadim9999 commented 6 years ago

@atherdon In this article I learn about declaration of arrays. Methods applied to arrays are push(), unshift(), shift(), slice(), splice(), pop(), forEach(), concat(), filter(), reduce() and other methods. let data3 = [ {name: "Raphel", gender: "male"}, {name: "Tom", gender: "male"}, {name: "Dorry", gender: "female"}, {name: "Suzie", gender: "female"}, ]; let genderwise = data3.reduce((acc,item,index) => { acc[item.gender].push(item); return acc; },{male:[],female:[],none:[]});// init accumulator console.log(genderwise); it's output data for two "branches" male and female. Also the function reduce() you can use like a searching of data. Must not use a function delete() with arrays because it's make holes intro.

atherdon commented 6 years ago

ok, please add lodash or underscore and explore how this libraries(they're pretty similar so pick one) are reducing pain of working with arrays

you don't need to explain me how each function from that library works, but try some by hands - i'm sure you'll like it

On 05-Jul-2018 at 02:44 PM, Vadim wrote:

@atherdon https://github.com/atherdon In this article I learn about declaration of arrays. Methods applied to arrays are push(), unshift(), shift(), slice(), splice(), pop(), forEach(), concat(), filter(), reduce() and other methods. let data3 = [ {name: "Raphel", gender: "male"}, {name: "Tom", gender: "male"}, {name: "Dorry", gender: "female"}, {name: "Suzie", gender: "female"}, ]; let genderwise = data3.reduce((acc,item,index) => { acc[item.gender].push(item); return acc; },{male:[],female:[],none:[]});// init accumulator console.log(genderwise); it's output data for two "branches" male and female. Also the function reduce() you can use like a searching of data. Must not use a function delete() with arrays because it's make holes intro.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vadim9999/js/issues/1#issuecomment-402746319, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDqzPmK0RjvIgqBOwgIRUViUD0aksks5uDiZJgaJpZM4U-Rds .

vadim9999 commented 6 years ago

@atherdon yes I like it. The lodash allow programmers to code faster.