Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. 1. Write a function to format time which accepts time in seconds and return a string with formatted time
  2.  
  3. e.g.
  4.  
  5. format_time(1)
  6. //=> "1 second"
  7. format_time(125)
  8. //=> "2 minutes, 5 seconds"
  9. format_time(2100)
  10. //=> "35 minutes"
  11. format_time(2115)
  12. //=> "35 minutes, 15 seconds"
  13.  
  14.  
  15.  
  16. 2. Write a function which will format price, input is a float number and returns a string with formatted price
  17. Example:
  18. format_price(1500.129)
  19. // => 'Rs 1,500.12'
  20. format_price(-5)
  21. // => 'Rs -5.00'
  22. format_price(1000000.5)
  23. // => 'Rs 1,000,000.50'
  24.  
  25.  
  26.  
  27. 3. Write a function to check if a string is a palindrome and returns 'Nes' or 'No'
  28.  
  29. e.g.
  30. is_palindrome("asdsa")
  31. //=> "Yes"
  32. is_palindrome("asddsa")
  33. //=> "Yes"
  34. is_palindrome("aaadaa")
  35. //=> "No"
  36.  
  37.  
  38. 4. Write a function to find the first non repeating letter(ignoring the case) in a given string
  39. e.g.
  40. first_non_repeating_letter("a")
  41. //=> "a"
  42. first_non_repeating_letter("stress")
  43. //=> "t"
  44. first_non_repeating_letter("moonmen")
  45. //=> "e"
  46. first_non_repeating_letter("stress stress")
  47. //=> " "
  48. first_non_repeating_letter("sTreSS")
  49. //=> "T"
  50.  
  51.  
  52. 5. Write a function to find perfect numbers between 1 to n, for given n
  53.  
  54. perfect_numbers(10)
  55. //=> [6]
  56. perfect_numbers(29)
  57. //=> [6,28]
  58. perfect_numbers(400)
  59. //=> [6,28]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement