- Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathArrayUtils.js
More file actions
Latest commit
32 lines (25 loc) · 903 Bytes
/
Copy pathArrayUtils.js
File metadata and controls
32 lines (25 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
vartitleCaseString=(data)=>
data
.toLowerCase()
.split(' ')
.map((word)=>`${word.charAt(0).toUpperCase()}${word.slice(1)}`)
.join(' ')
varconvertStringToArray=(para,removeSpaces=false)=>
removeSpaces ? [...para].filter((item)=>item!==' ') : [...para]
varcountInstanceInArray=(arr)=>
arr.reduce((obj,item)=>{
if(!obj[item])obj[item]=0
obj[item]++
returnobj
},{})
varsumOfAnArray=(arr,initialValue=0)=>
arr.reduce((a,b)=>a+b,initialValue)
varinArrayOfObjects=(arr,key,value)=>arr.find((ar)=>ar[key]===value)
varfindArrayIndex=(arr,key,value)=>
arr.findIndex((ar)=>ar[key]===value)
vargetUniqueList=(arr)=>
arr.filter(
(ar,index,list)=>
list.findIndex((p)=>JSON.stringify(ar)===JSON.stringify(p))===index
)
varshuffle=(arr)=>arr.sort(()=>0.5-Math.random());