MCPcopy Create free account
hub / github.com/course-dasheng/fe-algorithm / leftpad2

Function leftpad2

interview/leftpad.js:24–40  ·  view source on GitHub ↗
(str,length,ch)

Source from the content-addressed store, hash-verified

22// '00000000' 1
23
24function leftpad2(str,length,ch){
25 let len = length-str.length
26 total = ''
27 while(true){
28 // if(len%2==1){
29 if(len & 1){
30 total+=ch
31 }
32 if(len==1){
33 return total+str
34 }
35 ch += ch
36 len = len >> 1
37 // len = parseInt(len/2)
38 }
39
40}
41console.log(leftpad2('hello',10,'0'))
42
43

Callers 1

leftpad.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected