0

I am having trouble understanding what to do next. The following code removes all the duplicate numbers but I also need to remove the strings without converting them to numbers. I'm not sure how to proceed...

var arr = [ 10, 44, 55 ,66 , 77 , 55 , 44 , 3 , 3 , 3 , 4 , 5 , 6 , 54 , "henry", "33", "£", "66"]
var max = {};
function biggerThanMax(arr){
    return arr.filter(function(item,index){
        return arr.indexOf(item) >= index;
    });
};
biggerThanMax(arr)
4
  • 1
    Your array is missing the closing ] Commented Sep 3, 2018 at 15:42
  • 1
    ... and your function is missing a { Commented Sep 3, 2018 at 15:43
  • What should the output be? It's still a little bit vague what you want to achieve. By "remove the strings", do you mean remove all strings, or just the ones that are duplicates of an already existing number? Commented Sep 3, 2018 at 15:46
  • Should "33" be removed? Commented Sep 3, 2018 at 15:47

2 Answers 2

1

use typeof x to check the type of variable x

Sign up to request clarification or add additional context in comments.

Comments

1

You want to use typeof

var arr = [
  10, 44, 55, 66, 77, 55, 44,
  3, 3, 3, 4, 5, 6, 54,
  "henry", "33", "£", "66"
]
var max = {};

function biggerThanMax(arr) {
  return arr.filter(function(item, index) {
    return typeof item == 'number' && arr.indexOf(item) >= index;
  });
};
console.log(biggerThanMax(arr))


You also have a couple of typos (which are likely a typo in your example)

  • Unclosed array
  • Missing biggerThanMax opening bracket.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.