-
Notifications
You must be signed in to change notification settings - Fork 0
/
letterPositions.js
36 lines (25 loc) · 1003 Bytes
/
letterPositions.js
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
const assertEqual = function(actual, expected) {
if (actual !== expected) {
return `Assertion Failed: 🚩🚩🚩${actual} !== ${expected} 🚩🚩🚩` ;
} else {
return `Assertion Passed: 👍👍👍${actual} === ${expected}👍👍👍`;
}
};
const letterPositions = function(sentence) {
let val = sentence.split(' ').join("");
const results = {};
for(let i = 0; i < val.length; i++){
//val[i];
//console.log(val[i]);
//results[val[i]];
//console.log(results[val[i]]);
if(!results[val[i]]) // create to check the object if theres anything inside
{
results[val[i]] = []; // this creates an array at the location
}
results[val[i]].push(i); // that location is then push inside the object.
}
// logic to update results here
return results;
};
console.log(letterPositions("lighthouse in the house"));