forked from secoyawood/1.03-JavaScript-Arrays
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayProblems.js
More file actions
52 lines (40 loc) · 1.18 KB
/
Copy pathArrayProblems.js
File metadata and controls
52 lines (40 loc) · 1.18 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//problem 1
//create a for loop for the provided array. The for loop should increase all items by 1
//output = [2, 3, 4, 5, 6]
// const intArray = [1, 2, 3, 4, 5]
// for (index = 0; index < intArray.length; index++){
// return intArray[index]+1
// }
// console.log(intArray)
//problem 2
//using array methods, alter the given array to match the output
//output = [1, 2, 3, 4, 5]
// inputArray = [2, 3, 1, 5, 5, 6]
// const problem_2 = (array) => {
// array.pop()
// array.splice(2, 2, 4)
// array.splice(0, 0, 1)
// return array
// }
// console.log(problem_2(inputArray))
//problem 3
//using only three for loops
const csFirstUniqueChar = (input_str) => {
const array = input_str.split("")
for (index = 0; index < input_str.length; index++){
if (array[index] === array[index - 1]) {
} else if (array[index] === array[index + 1]) {
} else if (index != 0) {
return index
}
}
return false
}
console.log(csFirstUniqueChar('5558666'))
//output = '3'
/*
turn the string into an array
run the array through a loop to check each index
test each index against the next index
return the position of the different item
*/