-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
36 lines (35 loc) · 743 Bytes
/
array.js
File metadata and controls
36 lines (35 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// CyclicRotation
function solution(A, K) {
if (A.length>0 && K>0) {
for (let i=1; i<=K; i++){
let lastElement = A[A.length-1];
A.pop()
console.log(A)
A.unshift(lastElement)
}
}
return A
}
//OddOccurrencesInArray
function solution(A) {
let unpairedNum;
if (A.length === 1) {
return A[0]
}
let step = 2
if (A.length > 1){
A.sort()
unpairedNum = A[A.length-1]
for (let i=0; i<A.length-1; i+=step){
if (A[i] === A[i+1]) {
step = 2
}
if (A[i] !== A[i+1]) {
unpairedNum = A[i]
step = 1
}
}
}
console.log(unpairedNum )
return unpairedNum
}