Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Array helper method
- //finding a item from array
- // looping array
- //find
- //filter
- //every
- //some
- //findIndex
- //map
- //reduce
- //works on array
- //find
- //must working on array
- // must return something to get the result
- //results a (single) the matched value based on condition
- // const arr = [1, 3, 5, 7]
- // const result = arr.find((elm) => elm === 10)
- // console.log(result)
- //filter
- //must working on array
- // must return something to get the result
- //results a (single) the matched value based on condition
- // const arr = [1, 3, 5, 7]
- // const result = arr.filter((elm) => elm < 3)
- // console.log(result)
- //must working on array
- // must return something to get the result
- //results the index (single) matched value based on condition
- // const arr = [1, 3, 5, 7]
- // const result = arr.findIndex((elm) => elm === 3)
- // console.log(result)
- //must working on array
- // must return something to get the result
- //results an array having exact number of element(original source)
- // const arr = [1, 3, 5, 7]
- // const result = arr.map((elm) => elm * 3 )
- // console.log(result)
- //every
- //must working on array
- // must return something to get the result
- //results an true or false based on condition
- // const arr = [1, 3, 5, 7]
- // const result = arr.every((elm) => elm > 0 )
- // console.log(result)
- //some
- //must working on array
- // must return something to get the result
- //results an true or false based on condition
- // const arr = [1, 3, 5, 7]
- // const result = arr.some((elm) => elm > 10 )
- // console.log(result)
- //reduce
- //must working on array
- // must return something to get the result
- //results depends what you want to do!
- // 1 + 3 + 5 + 7
- // const arr = [1, 3, 5, 7]
- // // acc = 1, curr = 3 sum = 4
- // // acc = 4 curr = 5 sum = 9
- // // acc = 9 curr = 7 sum = 16
- // const result = arr.reduce(
- // (acc, curr) => {
- // console.log(acc, curr)
- // return {
- // sum: acc.sum + curr,
- // }
- // },
- // {
- // sum: 10,
- // }
- // )
- // console.log(result)
- // const arr = ['samim', 'Hasan']
- // const result = arr.reduce((prevVal, currentVal) => {
- // return prevVal + ' ' + currentVal
- // }, '')
- // console.log(result)
- //foreach
- //doesn't return anything
- // const arr = ['samim', 'Hasan']
- // let resultStr = ''
- // arr.forEach((elm) => resultStr += elm)
- // console.log(resultStr)
- //slice doesn't modifies original array
- //last index is exclusive
- // const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
- // console.log(animals.slice(2, 4));
- // console.log(animals)
- //splice modifies original array
- //last index is inclusive
- // const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']
- // console.log(animals.splice(2, 4))
- // console.log(animals)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement