This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const movieList = document.getElementById('movie-list') | |
| const search = document.getElementById('search') | |
| const main = document.getElementById('main') | |
| search.addEventListener('input', () => { | |
| const value = search.value.toLowerCase() | |
| const filtered = movies.filter(movie => { | |
| // title, genre, director, cast | |
| const title = movie.title.toLowerCase() | |
| const titleIncludes = title.includes(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| const grades = ['a', 'a', 'b', 'f', 'a', 'd', 'a', 'b', 'f'] | |
| for (let i = 0; i < grades.length; i++) { | |
| const grade = grades[i] | |
| console.log('traditional', grade) | |
| } | |
| for (const grade of grades) { | |
| console.log('of', grade) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const grades = ['a', 'a', 'b', 'a', 'd', 'a', 'b'] | |
| const uniqueGrades = new Set(grades) | |
| console.log('uniqueGrades', uniqueGrades) | |
| const uniqueGradesArray = [...uniqueGrades] | |
| console.log('uniqueGradesArray', uniqueGradesArray) | |
| const set = new Set() | |
| set.add(1) | |
| set.add('hello') | |
| set.add(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| function vehicleFactory (speed) { | |
| // 1. Declare a new object | |
| const vehicle = {} | |
| // 2. Customize the object | |
| vehicle.distance = 0 | |
| vehicle.speed = speed | |
| vehicle.travel = function () { | |
| vehicle.distance += vehicle.speed | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const roads = [ | |
| 'a-b', // ['a', 'b'] | |
| 'a-c', // ['a', 'c'] | |
| 'a-d', // ['a', 'd'] | |
| 'b-a', // ['b', 'a'] | |
| 'b-d', | |
| 'b-e', | |
| 'c-a', | |
| 'c-d', | |
| 'd-a', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Object containing budget categories and their initial budgets | |
| const categoryWiseBudget = { | |
| "Groceries": 2000, | |
| "Entertainment": 500, | |
| "Rent": 2000, | |
| "Utilities": 500, | |
| "Health": 2000, | |
| "Education": 1500, | |
| "Miscellaneous": 500 | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] | |
| const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] | |
| const characters = ['.', ':', ...letters, ...numbers, '!', '?'] | |
| console.log('characters', characters) | |
| const [firstLetter, secondLetter, thirdLetter, ...rest] = letters | |
| // Log the first three letters individually | |
| console.log('firstLetter', firstLetter, 'secondLetter', secondLetter, 'thirdLetter', thirdLetter) | |
| // Log the remaining letters as a single array | |
| console.log(rest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const paymentAPI = { | |
| async chargeCard(amount, cardNumber) { | |
| // In production, this calls a real payment processor | |
| await new Promise(resolve => setTimeout(resolve, 100)); | |
| if (cardNumber.startsWith('4')) { | |
| return { success: true, transactionId: 'txn_123', amount }; | |
| } | |
| throw new Error('Card declined'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. Interface for Magical Item | |
| interface IMagicalItem { | |
| name: string | |
| type: string | |
| powerLevel: number | |
| isRare: boolean | |
| } | |
| // 2. Class implementing IMagicalItem | |
| class MagicalItem implements IMagicalItem { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const o = { message: 'hi', count: 5 } | |
| // type Output = { | |
| // message: string | |
| // count: number | |
| // } | |
| type Output = typeof o | |
| const results = [] |
NewerOlder