function - What type of programming is this? -
i finished taking entry placement test computer science in college. passed, missed bunch of questions in specific category: variable assignment. want make sure understand before moving on.
it started out easy things, "set age equal age"
int age = 18, pretty simple
but then, had question had no clue how approach. went like...
"determine if character c is in alphabet , assign variable"
i function, issue is, gave me literally line write entire answer (so 50 characters max). here how answer box looked:
my first thought like
in_alphabet = function(c) { var alphabet = ["a", "b" ... "z"] if(alphabet.indexof(c) != -1) return true; }
but solution has 2 issues:
- how can set "c" value when whole function equal in_alphabet?
- i can't fit small answer box. 99% sure looking else. does know looking for? can't think of 1 line solution this
language doesn't matter (although solution in java/c++ preferred). appreciate guidance (doesn't have solution, don't know begin)
the question "determine if character c is in alphabet , assign variable" not ask create function (although in many languages best way this).
in r
like:
inalphabet <- c %in% letters
so can in 1 line in real-world languages. note letters
built-in list of characters.
Comments
Post a Comment