Advertisement
ansh2809

app.js

Jul 31st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", "Michael", "Robert", "Laura", "Anne", "Nige"],
  2. lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", "Suyama", "King", "Callahan", "Dodsworth", "White"],
  3. cities = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", "Philadelphia", "New York", "Seattle", "London", "Boston"],
  4. titles = ["Accountant", "Vice President, Sales", "Sales Representative", "Technical Support", "Sales Manager", "Web Designer",
  5. "Software Developer", "Inside Sales Coordinator", "Chief Techical Officer", "Chief Execute Officer"],
  6. birthDates = [new Date("1948/12/08"), new Date("1952/02/19"), new Date("1963/08/30"), new Date("1937/09/19"), new Date("1955/03/04"), new Date("1963/07/02"), new Date("1960/05/29"), new Date("1958/01/09"), new Date("1966/01/27"), new Date("1966/03/27")];
  7.  
  8. function createRandomData(count) {
  9. var data = [],
  10. now = new Date();
  11. for (var i = 0; i < count; i++) {
  12. var firstName = firstNames[Math.floor(Math.random() * firstNames.length)],
  13. lastName = lastNames[Math.floor(Math.random() * lastNames.length)],
  14. city = cities[Math.floor(Math.random() * cities.length)],
  15. title = titles[Math.floor(Math.random() * titles.length)],
  16. birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
  17. age = now.getFullYear() - birthDate.getFullYear();
  18.  
  19. data.push({
  20. Id: i + 1,
  21. FirstName: firstName,
  22. LastName: lastName,
  23. City: city,
  24. Title: title,
  25. BirthDate: birthDate,
  26. Age: age
  27. });
  28. }
  29. return data;
  30. }
  31.  
  32. function generatePeople(itemCount, callback) {
  33. var data = [],
  34. delay = 25,
  35. interval = 500,
  36. starttime;
  37.  
  38. var now = new Date();
  39. setTimeout(function() {
  40. starttime = +new Date();
  41. do {
  42. var firstName = firstNames[Math.floor(Math.random() * firstNames.length)],
  43. lastName = lastNames[Math.floor(Math.random() * lastNames.length)],
  44. city = cities[Math.floor(Math.random() * cities.length)],
  45. title = titles[Math.floor(Math.random() * titles.length)],
  46. birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
  47. age = now.getFullYear() - birthDate.getFullYear();
  48.  
  49. data.push({
  50. Id: data.length + 1,
  51. FirstName: firstName,
  52. LastName: lastName,
  53. City: city,
  54. Title: title,
  55. BirthDate: birthDate,
  56. Age: age
  57. });
  58. } while(data.length < itemCount && +new Date() - starttime < interval);
  59.  
  60. if (data.length < itemCount) {
  61. setTimeout(arguments.callee, delay);
  62. } else {
  63. callback(data);
  64. }
  65. }, delay);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement