Advertisement
ugochukwu15

Untitled

Sep 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //python code
  2. def new_list(n):
  3.     n_dict = {}
  4.     n_dict['words'] = []
  5.     n_dict['numbers'] = []
  6.  
  7.     for i in n:
  8.  
  9.         if i == str(i):
  10.             n_dict['words'].append(i)
  11.         else:
  12.             n_dict['numbers'].append(i)
  13.  
  14.     return n_dict
  15.  
  16. // javaScript
  17. function new_list(n){
  18.   var dict = {};
  19.   dict.words = [];
  20.   dict.numbers = [];
  21.  
  22.   for(var i in n){
  23.     if (i == str(i)){
  24.       dict.words.push(i);
  25.     }
  26.     else{
  27.       dict.numbers.push(i);
  28.     }
  29.   }
  30.   return dict;
  31. }
  32.  
  33. var m = ["book", 4, "hook", 4.5]
  34. console.log(new_list(m))
  35.  
  36. m = ["book", 4, "hook", 4.5]
  37. print(new_list(m))
  38. //my problem is the str function is not valid in javascript, what do should i use. i want the result to be
  39. dict = { 'words' : ["books", "hooks"], 'numbers': [4, 4.5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement