Use Array.apply to repeat a loop
In JavaScript we cannot easily repeat something N times, and
CoffeeScript's range loop compiles into complex JavaScript.
We could also use `Array.from({ length: N })`, but that's not supported
by old browsers like Internet Explorer 11.
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
App.Managers =
|
||||
|
||||
generatePassword: ->
|
||||
chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
|
||||
pass = ""
|
||||
x = 0
|
||||
while x < 12
|
||||
i = Math.floor(Math.random() * chars.length)
|
||||
pass += chars.charAt(i)
|
||||
x++
|
||||
return pass
|
||||
possible_chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
|
||||
|
||||
chars = Array.apply(null, length: 12).map ->
|
||||
i = Math.floor(Math.random() * possible_chars.length)
|
||||
possible_chars.charAt(i)
|
||||
|
||||
chars.join("")
|
||||
|
||||
togglePassword: (type) ->
|
||||
$("#user_password").prop "type", type
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
|
||||
App.Polls =
|
||||
generateToken: ->
|
||||
token = ""
|
||||
rand = ""
|
||||
for n in [0..5]
|
||||
rand = Math.random().toString(36).substr(2) # remove `0.`
|
||||
token = token + rand
|
||||
strings = Array.apply(null, length: 6).map ->
|
||||
Math.random().toString(36).substr(2) # remove `0.`
|
||||
|
||||
token = token.substring(0, 64)
|
||||
return token
|
||||
strings.join("").substring(0, 64)
|
||||
|
||||
replaceToken: (token) ->
|
||||
$(".js-question-answer").each ->
|
||||
|
||||
Reference in New Issue
Block a user