Skip to content

Commit

Permalink
Create mapAB3.java
Browse files Browse the repository at this point in the history
Modify and return the given map as follows: if exactly one of the keys "a" or "b" has a value in the map (but not both), set the other to have that same value in the map.

mapAB3({"a": "aaa", "c": "cake"}) → {"a": "aaa", "b": "aaa", "c": "cake"}
mapAB3({"b": "bbb", "c": "cake"}) → {"a": "bbb", "b": "bbb", "c": "cake"}
mapAB3({"a": "aaa", "b": "bbb", "c": "cake"}) → {"a": "aaa", "b": "bbb", "c": "cake"}
  • Loading branch information
mkprj5 authored Apr 2, 2017
1 parent 695b096 commit 6598986
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Map-1/mapAB3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Modify and return the given map as follows: if exactly one of the keys "a" or "b" has a value in the map (but not both), set the other to have that same value in the map.
mapAB3({"a": "aaa", "c": "cake"}) → {"a": "aaa", "b": "aaa", "c": "cake"}
mapAB3({"b": "bbb", "c": "cake"}) → {"a": "bbb", "b": "bbb", "c": "cake"}
mapAB3({"a": "aaa", "b": "bbb", "c": "cake"}) → {"a": "aaa", "b": "bbb", "c": "cake"}
*/
public Map<String, String> mapAB3(Map<String, String> map) {
if(map.containsKey("a") && !map.containsKey("b")) {
map.put("b" , map.get("a"));
}
if(map.containsKey("b") && !map.containsKey("a")) {
map.put("a" , map.get("b"));
}
return map;
}

0 comments on commit 6598986

Please sign in to comment.