注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
Twitch Online OA 總共 3題希望對各位朋友有幫助:
1. 考prototype:
You are given an array A consisting of N integers. Your task is to return an array of N objects that share the same prototype, each of whom should have a "value()" method, which called on i-th object should return the integer A[i].
The "value()" method of all objects must be the same method and it cannot be an own property of those objects (for an object O the following O.hasOwnProperty('value') should be false).
Write a function "solution" such that, given an array A of N integers, returns an array T of N JavaScript objects. For any two indices i, j < N, the following conditions should be true:
T[j].value() === A[j]
T[i].value === T[j].value
!T[i].hasOwnProperty('value')
!T[j].hasOwnProperty('value')
where T = solution(A).
For example, given A = [4, 2], your function should return such array T, that
T[0].value() === 4
T[1].value() === 2
T[0].value === T[1].value
!T[0].hasOwnProperty('value')
!T[1].hasOwnProperty('value')</tt>
Assume that:
- N is an integer within the range 1 to 200
- each element of array A is an integer within the range −9,007,199,254,740,991 to 9,007,199,254,740,991
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
sed, any one of them could be chosen.
Write a function:
function solution(S) such that, given a string S consisting of N characters, returns any string that can result from a sequence of transformations as described above.
For example, given string S = "ACCAABBC" the function may return "AC", because one of the possible sequences of transformations is as follows:
ACCAABBC -> AAABBC -> ABBC -> AC
Also, given string S = "ABCBBCBA" the function may return "", because one possible sequence of transformations is:
ABCBBCBA -> ABCCBA -> ABBA -> AA -> ""
Finally, for string S = "BABABA" the function must return "BABABA", because no rules can be applied to string S.
Write an efficient algorithm for the following assumptions:
string S consists only of the following characters: "A", "B" and/or "C".
|