Chuyển đến nội dung chính

freecodecamp: basic data structures

freecodecamp: basic data structures

I note passed challenge code for help.

Use an Array to Store a Collection of Data

"let yourArray=[1,true,"3",4,5]; // change this line"

 Access an Array's Contents Using Bracket Notation

"myArray[1]="bb";"

Add Items to an Array with push() and unshift()

" arr.unshift("I",2,"three");
arr.push(7,"VIII",9);"

 Remove Items from an Array with pop() and shift()

"let popped=arr.pop(); // change this line
let shifted=arr.shift(); // change this line"

Remove Items Using splice()

" // change code below this line
arr.splice(2,2);
// change code above this line"

Add Items Using splice()

" // change code below this line
arr.splice(0,2,'DarkSalmon','BlanchedAlmond');
// change code above this line
"

Copy Array Items Using slice()

" // change code below this line
arr= arr.slice(2,4);
return arr;"

Copy an Array with the Spread Operator

" // change code below this line
newArr.push([...arr]);
// change code above this line"

Combine Arrays with the Spread Operator

"let sentence=['learning',...fragment,'is','fun']; // change this line"

Check For The Presence of an Element With indexOf()

" // change code below this line
if(arr.indexOf(elem)=== -1)
return false;
else
return true;
// change code above this line"

Iterate Through All an Array's Items Using For Loops

" // change code below this line for(let i=0;i<arr.length;i++){ if(arr[i].indexOf(elem)== -1){ newArr.push(arr[i]); } } // change code above this line"

Create complex multi-dimensional arrays


" // change code below this line
['unshift', false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array'],
['mutate', 1327.98, 'splice', 'slice', 'push'],
[[[['deepest', 1.3849, 7], 'deeper'], 'deep'], 'depth']
// change code above this line"

Add Key-Value Pairs to JavaScript Objects

"// change code below this line
foods.bananas=13;
foods.grapes=35;
foods.strawberries=27;
// change code above this line"

 Modify an Object Nested Within an Object


"userActivity.data.online=45;"

Access Property Names with Bracket Notation

"return foods[scannedItem];"

Use the delete Keyword to Remove Object Properties

" delete foods.oranges;
delete foods.plums;
delete foods.strawberries;"

Check if an Object has a Property

" if('Alan','Jeff','Sarah','Ryan' in obj)
return true;
else
return false;"

Iterate Through the Keys of an Object with a for...in Statement


" let count=0;
for(let u in obj){
if(obj[u].online)
count+=1;
;
}
return count;"

Generate an Array of All Object Keys with Object.keys()

"return Object.keys(obj);"

Modify an Array Stored in an Object


"userObj.data.friends.push(friend); return userObj.data.friends;"

Nhận xét

Bài đăng phổ biến từ blog này

freecodecamp: React

freecodecamp: React step by step to practice Create a Simple JSX Element " const JSX = <h1>Hello JSX!</h1>; " Create a Complex JSX Element " const JSX=<div> <h1></h1> <p></p> <ul> <li></li> <li></li> <li></li> </ul> </div>; " Add Comments in JSX " const JSX = ( /* here in first time */ <div> <h1>This is a block of JSX</h1> <p>Here 's a subtitle</p> </div> ); " Render HTML Elements to the DOM " const JSX = ( <div id= 'challenge-node' > <h1>Hello World</h1> <p>Lets render this to the DOM</p> </div> ); // change code below this line ReactDOM.render(JSX,document.getElementById( 'challenge-node' )); " Define an HTML Class in JSX " cons

freecodecamp: Introduction to the JavaScript Algorithms and Data Structures Projects

freecodecamp: Introduction to the JavaScript Algorithms and Data Structures Projects go go far away from home, coder Palindrome Checker " function palindrome(str) { // Good luck! let reg=/\W|_/ig; let pure= str.replace(reg, '' ).toLowerCase(); console.log(pure); return pure===pure.split( '' ).reverse().join( '' ); } " Roman Numeral Converter " function convertToRoman(num) { let mapping={ "1000" : "M" , "900" : "CM" , "500" : "D" , "400" : "CD" , "100" : "C" , "90" : "XC" , "50" : "L" , "40" : "XL" , "10" : "X" , "9" : "IX" , "5" : "V" , "4" : "IV" , "1" : &quo